Re: Date pickers
Re: Date pickers
- Subject: Re: Date pickers
- From: Deivy Petrescu <email@hidden>
- Date: Mon, 08 Feb 2010 20:53:55 -0500
On 08/02/2010, at 20:20 , Shane Stanley wrote:
> Converting from NSDates to AS dates is problematic, as you probably noticed
> from the earlier thread on the subject. You can't just extract a string
> version of the date and say "date dateString" as you would in normal AS.
>
> As far as I can see -- and I might well be missing something -- the way to
> convert the date/time you see in a date picker to an equivalent AS date is
> to make an NSCalendar and use it to extract the various date components from
> the NSDate, make an AS date using current date, and then set its various
> properties to the values you extracted.
>
> So something like this:
>
> -- assume theNSDate contains an NSDate value
> -- make an instance of the current calendar
> set theCal to current application's NSCalendar's currentCalendar()
>
> -- build a list of the components we want
> set theComponents to ((current application's NSYearCalendarUnit as integer)
> ¬
> + (current application's NSMonthCalendarUnit as integer) ¬
> + (current application's NSDayCalendarUnit as integer) ¬
> + (current application's NSHourCalendarUnit as integer) ¬
> + (current application's NSMinuteCalendarUnit as integer) ¬
> + (current application's NSSecondCalendarUnit as integer) ¬
> )
> -- use the calendar to get the components from the date
> set theComponents to theCal's components_fromDate_(theComponents, theNSDate)
>
> -- set variables to the various components
> tell theComponents
> set theYear to |year|()
> set theMonth to |month|()
> set theDay to |day|()
> set theHour to hour()
> set theMinute to minute()
> set theSecond to |second|()
> end tell
>
> -- make an AS date and set the various properties
> set theASDate to current date
> set year of theASDate to theYear
> set month of theASDate to theMonth
> set day of theASDate to theDay
> set hours of theASDate to theHour
> set minutes of theASDate to theMinute
> set seconds of theASDate to theSecond
>
Shane,
First place thank you!
However, may be this is not exactly what I was looking for.
I am using date pickers so that the user could enter any date.
I see that I get an cocoa date when I log the input.
That is, this is a date that I have to read.
I could just use a text field and read it as string.
I think it would be more elegant to have an appropriate field.
When I run a test here is what I get:
<output>
run
[Switching to process 5965]
Running…
2010-02-08 19:42:40.425 OpenApp_Test[5965:a0f] 2010-01-01 00:00:00 -0500
</output>
where "2010-01-01 00:00:00 -0500" is the date that I want to capture.
I forgot whose trick it was to capture records as string using the error message in AS.
Well, it seems to be a way to go here... :)
I also now that there is a function --stringFromDate-- in cocoa, but it doesn't seem to work.
Deivy Petrescu
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden