conversion using utc bias is problematic because it changes every year by 
different governments. it can not work for a future date and will need a 
database to store previous years' timezone and daylight records.

26.03.2014, в 9:02, Pascal Jasmin <[email protected]> написал(а):

> oops I forgot to include the windows dll call.
> 
> this approach calculates the offset to utc once on load, and the uses the 
> offset as an adjustment to 6!:0.  libc would be useful too, but would not be 
> xplatform, and would lose J's time format, and access to other datetime 
> functions.
> 
> 
> getTimeZoneInfo=: 3 : 0
> 'tzstatus tzinfo'=. 'kernel32 GetTimeZoneInformation i *i'&cd <(,43#0)
> NB. read TIME_ZONE_INFORMATION structure
> tzinfo=. (1 (<:+/\ 1 16 4 1 16 4 1)}43#0) <;.2 tzinfo    NB. 4 byte J integers
> tzbias=. 0{:: tzinfo
> tzinfo=. _3]\ }. tzinfo                  NB. Standard info ,: Daylight info
> 'name date bias'=. i. 3                  NB. column labels for tzinfo
> tmp=. (6&u:)@(2&ic)&.> name {"1 tzinfo   NB. read names as unicode text
> tmp=. (0{a.)&taketo&.> tmp               NB. take to first NUL
> tzinfo=. tmp (<a:;name)}tzinfo           NB. amend TZ names
> tmp=. _1&ic@(2&ic)&.> date{"1 tzinfo     NB. read SYSTEMTIME structures
> tzinfo=. tmp (<a:;date)}tzinfo           NB. amend TZ dates
> 
> tzstatus;tzbias;<tzinfo
> )
> 
> 
> ----- Original Message -----
> From: bill lam <[email protected]>
> To: "[email protected]" <[email protected]>
> Cc: 
> Sent: Tuesday, March 25, 2014 8:48:44 PM
> Subject: Re: [Jprogramming] datetime utc mod
> 
> there should be some api in libc or windows dll to get utc time directly IIRC.
> 
> 
> 26.03.2014, в 2:30, Pascal Jasmin <[email protected]> написал(а):
> 
>> Here are additions I've made to datetime.ijs (addons/type)
>> 
>> utcnow_z_ '' returns utc time tested on mac and windows.
>> 
>> a question about 6!:0 ... when DST changes, will it report the changes 
>> without reloading J? Some OS change the time automatically, while others ask 
>> to change clock, or do they all ask?
>> 
>> Now_z_ =: 6!:0@:(''"_)
>> utcBIAS_z_ =: 3 : 0 '' NB. may bug on unix if loaded at turn of month/year,  
>> so redo.  Must reload on DST change
>> if. IFWIN do. 0,~ >1{ getTimeZoneInfo_rgsdatetime_ ''
>> elseif. IFIOS do. 0
>> elseif. 1 do.  t=. +/ 3600 60 1 * (2 3 4{6!:0'') -~ (0&".@:>@:(1&{),~ 
>> ".@:>@:{:@:;:@:>@:{.) ':' cut 2!:0 'date -u' 
>> if. 0=15|t do. t, 0 else.  0 ,~ +/ 3600 60 1 * (2 3 4{6!:0'') -~ 
>> (0&".@:>@:(1&{),~ ".@:>@:{:@:;:@:>@:{.) ':' cut 2!:0 'date -u'  end. end. 
>> )
>> utc_z_ =: tsPlus&utcBIAS 
>> utcnow_z_ =: utc@:Now ''"_
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to