on 4fdc19d help sign in
664 lines 9.2 kB history raw
1+++
2title = "3c: Urbit Time"
3weight = 23
4template = "doc.html"
5+++
7## `++year`
9Date to `@da`
11Accept a parsed date of form `[[a=? y=@ud] m=@ud t=tarp]` and produce
12its `@da` representation.
14#### Accepts
16`det` is a `date`
18#### Produces
20A `@da`.
22#### Source
24```hoon
25++ year
26 |= det=date
27 ^- @da
28 =+ ^= yer
29 ?: a.det
30 (add 292.277.024.400 y.det)
31 (sub 292.277.024.400 (dec y.det))
32 =+ day=(yawn yer m.det d.t.det)
33 (yule day h.t.det m.t.det s.t.det f.t.det)
34```
36#### Examples
38```
39> (year [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=4 s=57 f=~[0xd940]]])
40~2014.8.4..20.04.57..d940
41```
43---
45## `++yore`
47Date from atomic date
49Produces a `date` from a `@da`.
51#### Accepts
53`now` is a time atom, `@da`.
55#### Produces
57A `date`.
59#### Source
61```hoon
62++ yore
63 |= now=@da
64 ^- date
65 =+ rip=(yell now)
66 =+ ger=(yall d.rip)
67 :- ?: (gth y.ger 292.277.024.400)
68 [a=& y=(sub y.ger 292.277.024.400)]
69 [a=| y=+((sub 292.277.024.400 y.ger))]
70 [m.ger d.ger h.rip m.rip s.rip f.rip]
71```
73#### Examples
75```
76> (yore ~2014.6.6..21.09.15..0a16)
77[[a=%.y y=2.014] m=6 t=[d=6 h=21 m=9 s=15 f=~[0xa16]]]
78```
80---
82## `++yell`
84Tarp from atomic date
86Produce a [`$tarp`](/docs/hoon/reference/stdlib/2q#tarp) time format from a`@da`.
88#### Accepts
90`now` is a `@da`.
92#### Produces
94A `tarp`.
96#### Source
98```hoon
99++ yell
100 |= now=@d
101 ^- tarp
102 =+ sec=(rsh 6 now)
103 =+ ^= fan
104 =+ [muc=4 raw=(end 6 now)]
105 |- ^- (list @ux)
106 ?: |(=(0 raw) =(0 muc))
107 ~
108 => .(muc (dec muc))
109 [(cut 4 [muc 1] raw) $(raw (end [4 muc] raw))]
110 =+ day=(div sec day:yo)
111 => .(sec (mod sec day:yo))
112 =+ hor=(div sec hor:yo)
113 => .(sec (mod sec hor:yo))
114 =+ mit=(div sec mit:yo)
115 => .(sec (mod sec mit:yo))
116 [day hor mit sec fan]
117```
119#### Examples
121```
122> (yell ~2014.3.20..05.42.53..7456)
123[d=106.751.991.820.094 h=5 m=42 s=53 f=~[0x7456]]
125> (yell ~2014.6.9..19.09.40..8b66)
126[d=106.751.991.820.175 h=19 m=9 s=40 f=~[0x8b66]]
128> (yell ~1776.7.4)
129[d=106.751.991.733.273 h=0 m=0 s=0 f=~]
130```
132---
134## `++yule`
136Daily time to time atom
138Accepts a [`$tarp`](/docs/hoon/reference/stdlib/2q#tarp), a parsed daily time,
139and produces a `@da`.
141#### Accepts
143`rip` is a `tarp`.
145#### Produces
147A time atom, `@da`.
149#### Source
151```hoon
152++ yule
153 |= rip=tarp
154 ^- @d
155 =+ ^= sec ;: add
156 (mul d.rip day:yo)
157 (mul h.rip hor:yo)
158 (mul m.rip mit:yo)
159 s.rip
160 ==
161 =+ ^= fac =+ muc=4
162 |- ^- @
163 ?~ f.rip
164 0
165 => .(muc (dec muc))
166 (add (lsh [4 muc] i.f.rip) $(f.rip t.f.rip))
167 (con (lsh 6 sec) fac)
168```
170#### Examples
172```
173> =murica (yell ~1776.7.4)
175> murica
176[d=106.751.991.733.273 h=0 m=0 s=0 f=~]
178> (yule murica)
1790x8000000b62aaf5800000000000000000
181> `@da`(yule murica)
182~1776.7.4
184> `@da`(yule (yell ~2014.3.20..05.42.53..7456))
185~2014.3.20..05.42.53..7456
187> `tarp`[31 12 30 0 ~]
188[d=31 h=12 m=30 s=0 f=~]
190> `@dr`(yule `tarp`[31 12 30 0 ~])
191~d31.h12.m30
192```
194---
196## `++yall`
198Time since beginning of time
200Produce the date tuple of `[y=@ud m=@ud d=@ud]` of the year, month, and
201day from a number of days from the beginning of the Gregorian calendar.
203#### Accepts
205`day` is a `@ud`.
207#### Produces
209A cell of unsigned decimals.
211#### Source
213```hoon
214++ yall
215 |= day=@ud
216 ^- [y=@ud m=@ud d=@ud]
217 =+ [era=0 cet=0 lep=*?]
218 => .(era (div day era:yo), day (mod day era:yo))
219 => ^+ .
220 ?: (lth day +(cet:yo))
221 .(lep &, cet 0)
222 => .(lep |, cet 1, day (sub day +(cet:yo)))
223 .(cet (add cet (div day cet:yo)), day (mod day cet:yo))
224 =+ yer=(add (mul 400 era) (mul 100 cet))
225 |- ^- [y=@ud m=@ud d=@ud]
226 =+ dis=?:(lep 366 365)
227 ?. (lth day dis)
228 =+ ner=+(yer)
229 $(yer ner, day (sub day dis), lep =(0 (end [0 2] ner)))
230 |- ^- [y=@ud m=@ud d=@ud]
231 =+ [mot=0 cah=?:(lep moy:yo moh:yo)]
232 |- ^- [y=@ud m=@ud d=@ud]
233 =+ zis=(snag mot cah)
234 ?: (lth day zis)
235 [yer +(mot) +(day)]
236 $(mot +(mot), day (sub day zis))
237```
239#### Examples
241```
242> (yall 198)
243[y=0 m=7 d=17]
245> (yall 90.398)
246[y=247 m=7 d=3]
248> (yall 0)
249[y=0 m=1 d=1]
250```
252---
254## `++yawn`
256Days since beginning of time
258Inverse of `yall`, computes number of days A.D. from y/m/d date as the
259tuple `[yer=@ud mot=@ud day=@ud]`.
261#### Accepts
263`yer` is an unsigned decimal.
265`mon` is an unsigned decimal.
267`day` is an unsigned decimal.
269#### Produces
271An unsigned decimal.
273#### Source
275```hoon
276++ yawn
277 |= [yer=@ud mot=@ud day=@ud]
278 ^- @ud
279 => .(mot (dec mot), day (dec day))
280 => ^+ .
281 %= .
282 day
283 =+ cah=?:((yelp yer) moy:yo moh:yo)
284 |- ^- @ud
285 ?: =(0 mot)
286 day
287 $(mot (dec mot), cah (slag 1 cah), day (add day (snag 0 cah)))
288 ==
289 |- ^- @ud
290 ?. =(0 (mod yer 4))
291 =+ ney=(dec yer)
292 $(yer ney, day (add day ?:((yelp ney) 366 365)))
293 ?. =(0 (mod yer 100))
294 =+ nef=(sub yer 4)
295 $(yer nef, day (add day ?:((yelp nef) 1.461 1.460)))
296 ?. =(0 (mod yer 400))
297 =+ nec=(sub yer 100)
298 $(yer nec, day (add day ?:((yelp nec) 36.525 36.524)))
299 (add day (mul (div yer 400) (add 1 (mul 4 36.524))))
300```
302#### Examples
304```
305> (yawn 2.018 7 4)
306737.244
308> (yawn 1.776 7 4)
309648.856
311> (yawn 1.990 10 11)
312727.116
313```
315---
317## `++yelp`
319Leap year?
321Determines whether a year is a leap year. Produces a flag.
323#### Accepts
325`yer` is an unsigned decimal.
327#### Produces
329A flag.
331#### Source
333```hoon
334++ yelp
335 |= yer=@ud ^- ?
336 &(=(0 (mod yer 4)) |(!=(0 (mod yer 100)) =(0 (mod yer 400))))
337```
339#### Examples
341```
342> (yelp 2.014)
343%.n
345> (yelp 2.008)
346%.y
348> (yelp 0)
349%.y
351> (yelp 14.011)
352%.n
353```
355---
357## `++yo`
359Time constants core
361Core whose arms contain constants for interacting with earth time.
363#### Source
365```hoon
366++ yo
367```
369---
371### `++cet:yo`
373Days in a century
375Derived by multiplying the number of days in a year
376(365) by the number of years in a century (100), then adding the number
377days from leap-years in a century (24).
379#### Produces
381An atom.
383#### Source
385```hoon
386++ cet 36.524
387```
389#### Examples
391```
392> cet:yo
39336.524
395> (add 365 cet:yo)
39636.889
398> (sub (add 24 (mul 100 365)) cet:yo)
400```
402---
404### `++day:yo`
406Seconds in day
408The number of seconds in a day.
410#### Produces
412An atom.
414#### Source
416```hoon
417++ day 86.400
418```
420#### Examples
422```
423> day:yo
42486.400
426> (add 60 day:yo)
42786.460
428```
430---
432### `++era:yo`
434Leap-year period
436The number of days in a 400-year period, arrived at by multiplying `cet` by four
437and adding one. This is done because every 400 years, there is a leap-year where
438there would otherwise not be.
440#### Produces
442An atom.
444#### Source
446```hoon
447++ era 146.097
448```
450#### Examples
452```
453> era:yo
454146.097
456> (sub era:yo (mul 4 cet:yo))
458```
460#### Discussion
462A year is a leap-year if:
464- it's divisible by 4;
465- **unless** it's divisible by 100;
466- **or** if it's divisible by 400.
468---
470### `++hor:yo`
472Seconds in hour
474The number of seconds in an hour. Derived by multiplying the number of
475seconds in a minute by the minutes in an hour.
477#### Produces
479An atom.
481#### Source
483```hoon
484++ hor 3.600
485```
487#### Examples
489```
490> hor:yo
4913.600
493> (div hor:yo 60)
49460
495```
497---
499### `++jes:yo`
501Maximum 64-bit timestamp
503This is the number of days (starting from 1970) that can be represented in a
50464-bit timestamp. Derived by multiplying `era:yo` by 730,692,561.
506#### Produces
508An atom.
510#### Source
512```hoon
513++ jes 106.751.991.084.417
514```
516#### Examples
518```
519> jes:yo
520106.751.991.084.417
521```
523#### Discussion
525The date is December 4, 292,277,026,596.
527---
529### `++mit:yo`
531Seconds in minute
533The number of seconds in a minute.
535#### Produces
537An atom.
539#### Source
541```hoon
542++ mit 60
543```
545#### Examples
547```
548> mit:yo
54960
550```
552---
554### `++moh:yo`
556Days in month
558The days in each month of the Gregorian common year. A list of unsigned
559decimal atoms (Either 28, 30, or 31) denoting the number of days in the
560month at the year at that index.
562#### Produces
564A `list` of `@ud`
566#### Source
568```hoon
569++ moh `(list @ud)`[31 28 31 30 31 30 31 31 30 31 30 31 ~]
570```
572#### Examples
574```
575> moh:yo
576~[31 28 31 30 31 30 31 31 30 31 30 31]
578> (snag 4 moh:yo)
57931
580```
582---
584### `++moy:yo`
586Days in months of leap-year
588The days in each month of the Gregorian leap-year. A list of unsigned
589decimal atoms (Either 29, 30, or 31) denoting the number of days in the
590month at the leap-year at that index.
592#### Produces
594A `list` of `@ud`.
596#### Source
598```hoon
599++ moy `(list @ud)`[31 29 31 30 31 30 31 31 30 31 30 31 ~]
600```
602#### Examples
604```
605> moy:yo
606~[31 29 31 30 31 30 31 31 30 31 30 31]
608> (snag 1 moy:yo)
60929
610```
612---
614### `++qad:yo`
616Seconds in 4 years
618The number of seconds in four years. Derived by adding one second to the
619number of seconds in four years.
621#### Produces
623An atom.
625#### Source
627```hoon
628++ qad 126.144.001
629```
631#### Examples
633```
634> qad:yo
635126.144.001
636```
638---
640### `++yer:yo`
642Seconds in year
644The number of seconds in a year. Derived by multiplying the number of
645seconds in a day by 365.
647#### Produces
649An atom.
651#### Source
653```hoon
654++ yer 31.536.000
655```
657#### Examples
659```
660> yer:yo
66131.536.000
662```
664---