DOC =: 0 : 0
Exported functions:
mnth days_in_month y -> int, days in month mnth, year y
is_leap_year y -> bool, uses Julian calendar before 1582
is_valid_ymd y m d -> bool, checks correctness of y m d
is_ut_dn dn -> bool, tjd between 1970.1.1 and 2038.1.18
is_ut_year y -> bool, y between 1970 and 2038
dn4ymd y m d -> dn, y can be 0 _1 _2 etc, m and d <0, >12 31
ymd4dn dn -> y m d
wd4dn dn -> wd, week day, 0..6 for Sun to Sat
wd_4dn dn -> wd, week day, 1..7 for Mon to Sun
df4hms h m s -> df, fraction of day
hms4df df -> h m s
dnf4ymdhms y m d h m s -> dnf
ymdhms4dnf dnf -> y m d h m s
[tz] jd4dnf dnf -> jd, julian day for (GMT) timezone
[tz] dnf4jd jd -> dnf, dnf for given julian day
ymd_now'' -> y m d, current local date
hms_now'' -> h m s, current local time
dn_now'' -> dn, current local dn
dnf_now'' -> dnf, current local dnf
jd_now tz -> jd, considering current (given) timezone
s4hms h m s -> 'HH:MM:SS'
s4ymd y m d -> 'YYYY.MM.DD'
s4ymdhms y m d h m s -> 'YYYY.MM.DD HH:MM:SS'
s4dnf dnf -> 'YYYY.MM.DD HH:MM:SS'
tz s4jd jd -> 'YYYY.MM.DD HH:MM:SS'
ensure_workday dn -> dn, shift to Mon from Sat,Sun
n wd nth_day_of_month y m -> dn, n-th (0=last) weekday wd in month m, year y
ut4jd jd -> ut, unix time
jd4ut ut -> jd, julian day from unix time
moonphase4jd jd -> float, moon phase day, 0..29.5+-0.3, max +-0.6
mpx'' -> prints some moon phase data, experimental; see moon.ijs
getTimeZoneInfo'' -> daylightsaving;offsetminutes;windowstzinfo
Data types:
dn - day number, TJD, 1970.1.1 = 587, usually integer
dnf - TJD+fraction
jd - julian day, dn+2440000.5, _4712.1.1 noon = 0, 2000.1.1 noon = 2451545.0
ut - unix time, 1970.1.1 00:00:00 = 0
jd and ut are absolute moments! others are relative (by default - local)
)
DNMIN =: 587
DNMAX =: 25441
DNMOON =: 29.53058867
MDAYS =: 0 31 28 31 30 31 30 31 31 30 31 30 31
is_ut_dn =: 3 : '(DNMIN <: y) *. y <: DNMAX'
is_ut_year =: 3 : '(1970 <: y) *. y <: 2038'
TODO
is_leap_year =: 3 : 'if. y<1582 do. 0=4|y else. (0=400|y)+.(0~:100|y)*.0=4|y end.'
days_in_month =: 4 : 'if. (is_leap_year y) *. x=2 do. 29 else. x{MDAYS end.'
is_valid_ymd =: 3 : 0
'y m d' =. y
if. (d<1)+.(m<1)+.m>12 do. 0 return. end.
if. y=1582 do.
if. (5<:d)*.(d<:14)*.m=10 do. 0 return. end.
end.
if. d<:m{MDAYS do. 1 return. end.
if. d>29 do. 0 return. end.
is_leap_year y
)
TODO
dn4ymd =: 3 : 0
'year month day' =. y
b =. 0
if. month > 12 do.
year =. year + <.month%12
month =. 12|month
elseif. month < 1 do.
month =. -month
year =. year - >:<.month%12
month =. 12 - 12|month
end.
if. month < 3 do.
year =. year - 1
month =. month + 12
end.
if. 15821014 < (year*10000) + (month*100) + day do.
b =. 2 - (<.year%100) - <.year%400
end.
_719006 + (<.4%~1461*year) + (<.30.6001*>:month) + day + b
)
ymd4dn =: 3 : 0
jdi =. y + 2440000
if. jdi < 2299160 do.
b =. jdi + 1525
else.
alpha =. <. (_7468861 + 4*jdi)%146097
b =. jdi + 1526 + alpha - <.alpha%4
end.
c =. <.(_2442 + 20*b)%7305
d =. <.(1461*c)%4
e =. <.(b - d)%30.6001
day =. (b - d) - <.30.6001*e
if. e < 14 do. month =. e - 1 else. month =. e - 13 end.
if. month > 2 do. year =. c - 4716 else. year =. c - 4715 end.
year,month,day
)
wd4dn =: 7|5+]
wd_4dn =: 1+7|4+]
df4hms =: +/ @: %&24 1440 86400
hms4df =: 3 : 0
y =. y - h =. <.y =. y * 24
y =. y - m =. <.y =. y * 60
h,m,y*60
)
dnf4ymdhms =: 3 : '(dn4ymd 3{.y)+df4hms 3}.y'
ymdhms4dnf =: 3 : '(ymd4dn d),hms4df y-d=.<.y'
jd4dnf =: 3 : 0
y+2440000.5
:
y+2440000.5-x%24.0
)
dnf4jd =: 3 : 0
y-2440000.5
:
y-2440000.5-x%24.0
)
moonphase4jd =: 3 : 'DNMOON|y-2449128.59'
0 : 0
delta_t = sdate - 2415021.0 # JDN for (1900,1,1,12:00)
t = delta_t / 36525.0
t2 = t * t; t3 = t2 * t
p = 2415020.75933 + c.synodic_month*k + 0.0001178*t2 - 0.000000155*t3
return p + 0.00033*dsin(166.56 + 132.87*t - 0.009173*t2)
)
ymd_now =: 3 : '3{.6!:0'''''
hms_now =: 3 : '3}.6!:0'''''
dn_now =: 3 : 'dn4ymd 3{.6!:0'''''
dnf_now =: 3 : '(dn4ymd 3{.t) + df4hms 3}.t=.6!:0'''''
jd_now =: 3 : 'y jd4dnf dnf_now'''''
s4hms =: [:}.[:,'r<:0>3.0'8!:2]
s4ymd =: 3 : '(":{.y),,''r<.0>3.0''8!:2}.y'
s4ymdhms =: 3 : '(s4ymd 3{.y),'' '',s4hms 3}.y'
s4dnf =: 3 : 's4ymdhms ymdhms4dnf y'
s4jd =: 4 : 's4dnf x dnf4jd y'
ut4jd =: *&86400 @ -&2440587.5
jd4ut =: +&2440587.5 @ %&86400
ensure_workday =: 3 : 'y++/1 2*0 6=wd4dn y'
nth_day_of_month =: 4 : 0
'n w'=.x
dn =. dn4ymd y,1
wd =. wd4dn dn
d =. >:w-wd
if. d<1 do. d =. d+7 end.
dn =. dn+d-1
if. n>0 do.
dn =. dn+(n-1)*7
else.
ymd =. ymd4dn dn =. dn+28
if. (1{y)~:1{ymd do. dn =. dn-7 end.
end.
dn
)
mpx =: 3 : 0
j =. 3 jd4dnf dnf_now ''
mp =. moonphase4jd j
np =. DNMOON-mp
mph =. nph =. ''
if. mp<1 do. mph =. '/',(0j1":mp*24),'h' end.
if. np<1 do. nph =. '/',(0j1":np*24),'h' end.
echo (0j1":mp*100%DNMOON),'% ',(0j2":mp),mph,' (',(0j2":np),nph,')'
)
getTimeZoneInfo=: 3 : 0
'tzstatus tzinfo'=. 'kernel32 GetTimeZoneInformation i *i'&cd <(,43#0)
tzinfo=. (1 (<:+/\ 1 16 4 1 16 4 1)}43#0) <;.2 tzinfo
tzbias=. 0{:: tzinfo
tzinfo=. _3]\ }. tzinfo
'name date bias'=. i. 3
tmp=. (6&u:)@(2&ic)&.> name {"1 tzinfo
tmp=. (0{a.)&taketo&.> tmp
tzinfo=. tmp (<a:;name)}tzinfo
tmp=. _1&ic@(2&ic)&.> date{"1 tzinfo
tzinfo=. tmp (<a:;date)}tzinfo
tzstatus;tzbias;<tzinfo
)