Re: Date pickers
Re: Date pickers
- Subject: Re: Date pickers
- From: Deivy Petrescu <email@hidden>
- Date: Tue, 09 Mar 2010 17:26:08 -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 Stanley <email@hidden>
> AppleScript Pro, April 2010, Florida <http://www.applescriptpro.com>
Apologies for returning to this subject, but in my app I have to do to many calculation with dates.
And from many testes I've run, there is nothing like adding days to a date in Obj-C.
Unless of course the date is the current date, but any date in the form "7/7/7" will not work.
I hear what you guys say, but the only workaround was to use the terminal.
The date command can come in handy (more man date)
Here are some examples (run from terminal):
"date -v7d -v7m -v7y"
-->Sat 7 Jul 2007 17:22:55 EDT
and
"date -v7d -v7m -v7y -v+1d"
--> Sun 8 Jul 2007 17:24:24 EDT
Hope this helps.
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