on c19bc7a help sign in
652 lines 10.0 kB history raw
1:- :~ navhome/'/docs/'
2 sort/'23'
3 title/'3c: Urbit Time'
4 ==
6;>
8# 3c: urbit time
10### `++yall`
12Time since beginning of time
14Produce the date tuple of `[y=@ud m=@ud d=@ud]` of the year, month, and
15day from a number of days from the beginning of the Gregorian calendar.
17#### Accepts
19`day` is a an unsigned decimal.
21#### Produces
23A cell of unsigned decimals.
25#### Source
27```
28 ++ yall
29 |= day=@ud
30 ^- [y=@ud m=@ud d=@ud]
31 =+ [era=0 cet=0 lep=*?]
32 => .(era (div day era:yo), day (mod day era:yo))
33 => ^+ .
34 ?: (lth day +(cet:yo))
35 .(lep &, cet 0)
36 => .(lep |, cet 1, day (sub day +(cet:yo)))
37 .(cet (add cet (div day cet:yo)), day (mod day cet:yo))
38 =+ yer=(add (mul 400 era) (mul 100 cet))
39 |- ^- [y=@ud m=@ud d=@ud]
40 =+ dis=?:(lep 366 365)
41 ?. (lth day dis)
42 =+ ner=+(yer)
43 $(yer ner, day (sub day dis), lep =(0 (end 0 2 ner)))
44 |- ^- [y=@ud m=@ud d=@ud]
45 =+ [mot=0 cah=?:(lep moy:yo moh:yo)]
46 |- ^- [y=@ud m=@ud d=@ud]
47 =+ zis=(snag mot cah)
48 ?: (lth day zis)
49 [yer +(mot) +(day)]
50 $(mot +(mot), day (sub day zis))
51```
53#### Examples
55```
56 > (yall 198)
57 [y=0 m=7 d=17]
59 > (yall 90.398)
60 [y=247 m=7 d=3]
62 > (yall 0)
63 [y=0 m=1 d=1]
64```
67---
68### `++yawn`
70Days since beginning of time
72Inverse of `yall`, computes number of days A.D. from y/m/d date as the
73tuple `[yer=@ud mot=@ud day=@ud]`.
75#### Accepts
77`yer` is an unsigned decimal.
79`mon` is an unsigned decimal.
81`day` is an unsigned decimal.
83#### Produces
85An unsigned decimal.
87#### Source
89```
90 ++ yawn
91 |= [yer=@ud mot=@ud day=@ud]
92 ^- @ud
93 => .(mot (dec mot), day (dec day))
94 => ^+ .
95 %= .
96 day
97 =+ cah=?:((yelp yer) moy:yo moh:yo)
98 |- ^- @ud
99 ?: =(0 mot)
100 day
101 $(mot (dec mot), cah (slag 1 cah), day (add day (snag 0 cah)))
102 ==
103 |- ^- @ud
104 ?. =(0 (mod yer 4))
105 =+ ney=(dec yer)
106 $(yer ney, day (add day ?:((yelp ney) 366 365)))
107 ?. =(0 (mod yer 100))
108 =+ nef=(sub yer 4)
109 $(yer nef, day (add day ?:((yelp nef) 1.461 1.460)))
110 ?. =(0 (mod yer 400))
111 =+ nec=(sub yer 100)
112 $(yer nec, day (add day ?:((yelp nec) 36.525 36.524)))
113 (add day (mul (div yer 400) (add 1 (mul 4 36.524))))
114```
116#### Examples
118```
119 > (yawn 2.018 7 4)
120 737.244
122 > (yawn 1.776 7 4)
123 648.856
125 > (yawn 1.990 10 11)
126 727.116
127```
129---
130### `++year`
132Date to @d
134Accept a parsed date of form `[[a=? y=@ud] m=@ud t=tarp]` and produce
135its `@d` representation.
137#### Accepts
139`det` is a `date`
141#### Produces
143A `@d`.
145#### Source
147```
148 ++ year
149 |= det=date
150 ^- @da
151 =+ ^= yer
152 ?: a.det
153 (add 292.277.024.400 y.det)
154 (sub 292.277.024.400 (dec y.det))
155 =+ day=(yawn yer m.det d.t.det)
156 (yule day h.t.det m.t.det s.t.det f.t.det)
157```
159#### Examples
161```
162 > (year [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=4 s=57 f=~[0xd940]]])
163 0x8000000d227df4e9d940000000000000
164```
166---
167### `++yell`
169Tarp from atomic date
171Produce a parsed daily time format from, `@d`, an atomic date.
173#### Accepts
175`now` is a `@d`.
177#### Produces
179A `tarp`.
181#### Source
183```
184 ++ yell
185 |= now=@d
186 ^- tarp
187 =+ sec=(rsh 6 1 now)
188 =+ ^= fan
189 =+ [muc=4 raw=(end 6 1 now)]
190 |- ^- (list @ux)
191 ?: |(=(0 raw) =(0 muc))
192 ~
193 => .(muc (dec muc))
194 [(cut 4 [muc 1] raw) $(raw (end 4 muc raw))]
195 =+ day=(div sec day:yo)
196 => .(sec (mod sec day:yo))
197 =+ hor=(div sec hor:yo)
198 => .(sec (mod sec hor:yo))
199 =+ mit=(div sec mit:yo)
200 => .(sec (mod sec mit:yo))
201 [day hor mit sec fan]
202```
204#### Examples
206```
207 > (yell ~2014.3.20..05.42.53..7456)
208 [d=106.751.991.820.094 h=5 m=42 s=53 f=~[0x7456]]
210 > (yell ~2014.6.9..19.09.40..8b66)
211 [d=106.751.991.820.175 h=19 m=9 s=40 f=~[0x8b66]]
213 > (yell ~1776.7.4)
214 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
215```
217---
218### `++yelp`
220Leap-week?
222Determines whether a year contains an ISO 8601 leap-week. Produces a flag.
224#### Accepts
226`yer` is an unsigned decimal.
228#### Produces
230A flag.
232#### Source
234```
235 ++ yelp
236 |= yer=@ud ^- ?
237 &(=(0 (mod yer 4)) |(!=(0 (mod yer 100)) =(0 (mod yer 400))))
238```
240#### Examples
242```
243 > (yelp 2.014)
244 %.n
246 > (yelp 2.008)
247 %.y
249 > (yelp 0)
250 %.y
252 > (yelp 14.011)
253 %.n
254```
256---
257### `++yore`
259Date from atomic date
261Produces a `date` from a `@d`.
263#### Accepts
265`now` is a time atom, `@d`.
267#### Produces
269A `date`.
271#### Source
273```
274 ++ yore
275 |= now=@da
276 ^- date
277 =+ rip=(yell now)
278 =+ ger=(yall d.rip)
279 :- ?: (gth y.ger 292.277.024.400)
280 [a=& y=(sub y.ger 292.277.024.400)]
281 [a=| y=+((sub 292.277.024.400 y.ger))]
282 [m.ger d.ger h.rip m.rip s.rip f.rip]
283```
285#### Examples
287```
288 > (yore ~2014.6.6..21.09.15..0a16)
289 [[a=%.y y=2.014] m=6 t=[d=6 h=21 m=9 s=15 f=~[0xa16]]]
290```
292---
293### `++yule`
295Daily time to time atom
297Accepts a `tarp`, a parsed daily time, and produces a time atom,
298`@d`.
300#### Accepts
302`rip` is a `tarp`.
304#### Produces
306A time atom, `@d`.
308#### Source
310```
311 ++ yule :: time atom
312 |= rip=tarp
313 ^- @d
314 =+ ^= sec ;: add
315 (mul d.rip day:yo)
316 (mul h.rip hor:yo)
317 (mul m.rip mit:yo)
318 s.rip
319 ==
320 =+ ^= fac =+ muc=4
321 |- ^- @
322 ?~ f.rip
323 0
324 => .(muc (dec muc))
325 (add (lsh 4 muc i.f.rip) $(f.rip t.f.rip))
326 (con (lsh 6 1 sec) fac)
327 ::
328```
330#### Examples
332```
333 > =murica (yell ~1776.7.4)
335 > murica
336 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
338 > (yule murica)
339 0x8000000b62aaf5800000000000000000
341 > `@da`(yule murica)
342 ~1776.7.4
344 > `@da`(yule (yell ~2014.3.20..05.42.53..7456))
345 ~2014.3.20..05.42.53..7456
347 > `tarp`[31 12 30 0 ~]
348 [d=31 h=12 m=30 s=0 f=~]
350 > `@dr`(yule `tarp`[31 12 30 0 ~])
351 ~d31.h12.m30
352```
354---
355### `++yo`
357Time constants core
359Core whose arms contain constants for interacting with earth time.
361#### Source
363```
364 ++ yo
365```
367---
368### `++cet:yo`
370Days in a century
372Derived by multiplying the number of days in a year
373(365) by the number of years in a century (100), then adding the number
374days from leap-years in a century (24).
376#### Produces
378An atom.
380#### Source
382```
383 |% ++ cet 36.524
384```
386#### Examples
388```
389 > cet:yo
390 36.524
392 > (add 365 cet:yo)
393 36.889
395 > (sub (add 24 (mul 100 365)) cet:yo)
396 0
397```
399---
400### `++day:yo`
402Seconds in day
404The number of seconds in a day.
406#### Produces
408An atom.
410#### Source
412```
413 ++ day 86.400
414```
416#### Examples
418```
419 > day:yo
420 86.400
422 > (add 60 day:yo)
423 86.460
424```
426---
427### `++era:yo`
429Leap-year period
431The number of days in a 400-year period, arrived at by multiplying `cet` by four
432and adding one. This is done because every 400 years, there is a leap-year where
433there would otherwise not be.
435#### Produces
437An atom.
439#### Source
441```
442 ++ era 146.097
443```
445#### Examples
447```
448 > era:yo
449 146.097
451 > (sub era:yo (mul 4 cet:yo))
452 1
453```
455#### Discussion
457A year is a leap-year if:
459- it's divisible by 4;
460- *unless* it's divisible by 100;
461- *or* if it's divisible by 400.
463---
464### `++hor:yo`
466Seconds in hour
468The number of seconds in an hour. Derived by multiplying the number of
469seconds in a minute by the minutes in an hour.
471#### Produces
473An atom.
475#### Source
477```
478 ++ hor 3.600
479```
481#### Examples
483```
484 > hor:yo
485 3.600
487 > (div hor:yo 60)
488 60
489```
491---
492### `++jes:yo`
494Maximum 64-bit timestamp
496This is the number of days (starting from 1970) that can be represented in a
49764-bit timestamp. Derived by multiplying `era:yo` by 730,692,561.
499#### Produces
501An atom.
503#### Source
505```
506 ++ jes 106.751.991.084.417
507```
509#### Examples
511```
512 > jes:yo
513 106.751.991.084.417
514```
516#### Discussion
518The date is December 4, 292,277,026,596.
520---
521### `++mit:yo`
523Seconds in minute
525The number of seconds in a minute.
527#### Produces
529An atom.
531#### Source
533```
534 ++ mit 60
535```
537#### Examples
539```
540 > mit:yo
541 60
542```
544---
545### `++moh:yo`
547Days in month
549The days in each month of the Gregorian common year. A list of unsigned
550decimal atoms (Either 28, 30, or 31) denoting the number of days in the
551month at the year at that index.
553#### Produces
555A `list` of `@ud`
557#### Source
559```
560 ++ moh `(list @ud)`[31 28 31 30 31 30 31 31 30 31 30 31 ~]
561```
563#### Examples
565```
566 > moh:yo
567 ~[31 28 31 30 31 30 31 31 30 31 30 31]
569 > (snag 4 moh:yo)
570 31
571```
573---
574### `++moy:yo`
576Days in months of leap-year
578The days in each month of the Gregorian leap-year. A list of unsigned
579decimal atoms (Either 29, 30, or 31) denoting the number of days in the
580month at the leap-year at that index.
582#### Produces
584A `list` of `@ud`.
586#### Source
588```
589 ++ moy `(list @ud)`[31 29 31 30 31 30 31 31 30 31 30 31 ~]
590```
592#### Examples
594```
595 > moy:yo
596 ~[31 29 31 30 31 30 31 31 30 31 30 31]
598 > (snag 1 moy:yo)
599 29
600```
602---
603### `++qad:yo`
605Seconds in 4 years
607The number of seconds in four years. Derived by adding one second to the
608number of seconds in four years.
610#### Produces
612An atom.
614#### Source
616```
617 ++ qad 126.144.001
618```
620#### Examples
622```
623 > qad:yo
624 126.144.001
625```
627---
628### `++yer:yo`
630Seconds in year
632The number of seconds in a year. Derived by multiplying the number of
633seconds in a day by 365.
635#### Produces
637An atom.
639#### Source
641```
642 ++ yer 31.536.000
643```
645#### Examples
647```
648 > yer:yo
649 31.536.000
650```
652---