• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Time offset for future dates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Time offset for future dates


  • Subject: Re: Time offset for future dates
  • From: Takaaki Naganoya <email@hidden>
  • Date: Mon, 18 Dec 2017 23:57:52 +0900

> 2017/12/18 22:06、Jörgen Stahle <email@hidden>のメール:
>
> Hi, guys!
> I need to be able to make a correct datetime string like
> "2017-12-18T09:59:35+01:00” for FUTURE dates. My problem is to take daylight
> savings shift into account when calculating time offset for a given time zone
> (CET in my case) for dates in the future.
> You cannot use the AppleScript command ’time to GMT’ relatively to another
> datetime than the current, and I haven’t found any shell script command that
> can do that.
> Of course I can make a function that give me the dates for the shiftings
> (last Sunday in march and October) and conditionally relate the time offset
> to the two periods. But is there an easier and more future proof way to do
> it?
> I think there might be ways to do this using Objective-C – or is there not?
> Anyway my skills knowledge in Objective-C (and Swift) is close to zero.
> Anyone that have a solution for me?
> Best regards
> Jörgen

Enjoy!

<AppleScript>
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

set aDate to getDateInternational(2018, 2, 1) of me ——year, month, date
set bStr to retISO8601DateTimeString(aDate, "CET") as string
-->     "2018-01-31T16:00:00+0100"

--NSDate -> ISO8601 Date & Time String
on retISO8601DateTimeString(targDate, timeZoneName)
        set theNSDateFormatter to current application's NSDateFormatter's
alloc()'s init()
        theNSDateFormatter's setDateFormat:"yyyy-MM-dd'T'HH:mm:ssZZZ"
        theNSDateFormatter's setTimeZone:(current application's NSTimeZone's
alloc()'s initWithName:timeZoneName)
        return (theNSDateFormatter's stringFromDate:targDate) as text
end retISO8601DateTimeString

--Make Date Object from parameters
on getDateInternational(aYear, aMonth, aDay)
        set theNSCalendar to current application's NSCalendar's
currentCalendar()
        set theDate to theNSCalendar's dateWithEra:1 |year|:aYear
|month|:aMonth |day|:aDay hour:0 minute:0 |second|:0 nanosecond:0
        return theDate as date
end getDateInternational
</AppleScript>

--
Takaaki Naganoya
email@hidden
http://piyocast.com/as/



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Time offset for future dates
      • From: Shane Stanley <email@hidden>
References: 
 >Time offset for future dates (From: Jörgen Stahle <email@hidden>)

  • Prev by Date: Time offset for future dates
  • Next by Date: Re: Time offset for future dates
  • Previous by thread: Time offset for future dates
  • Next by thread: Re: Time offset for future dates
  • Index(es):
    • Date
    • Thread