on dc20522 help sign in
649 lines 10 kB history raw
1+++
2title = "3c: Urbit Time"
3weight = 23
4template = "doc.html"
5+++
7### `++yall`
9Time since beginning of time
11Produce the date tuple of `[y=@ud m=@ud d=@ud]` of the year, month, and
12day from a number of days from the beginning of the Gregorian calendar.
14#### Accepts
16`day` is a an unsigned decimal.
18#### Produces
20A cell of unsigned decimals.
22#### Source
24```hoon
25 ++ yall
26 |= day=@ud
27 ^- [y=@ud m=@ud d=@ud]
28 =+ [era=0 cet=0 lep=*?]
29 => .(era (div day era:yo), day (mod day era:yo))
30 => ^+ .
31 ?: (lth day +(cet:yo))
32 .(lep &, cet 0)
33 => .(lep |, cet 1, day (sub day +(cet:yo)))
34 .(cet (add cet (div day cet:yo)), day (mod day cet:yo))
35 =+ yer=(add (mul 400 era) (mul 100 cet))
36 |- ^- [y=@ud m=@ud d=@ud]
37 =+ dis=?:(lep 366 365)
38 ?. (lth day dis)
39 =+ ner=+(yer)
40 $(yer ner, day (sub day dis), lep =(0 (end 0 2 ner)))
41 |- ^- [y=@ud m=@ud d=@ud]
42 =+ [mot=0 cah=?:(lep moy:yo moh:yo)]
43 |- ^- [y=@ud m=@ud d=@ud]
44 =+ zis=(snag mot cah)
45 ?: (lth day zis)
46 [yer +(mot) +(day)]
47 $(mot +(mot), day (sub day zis))
48```
50#### Examples
52```
53 > (yall 198)
54 [y=0 m=7 d=17]
56 > (yall 90.398)
57 [y=247 m=7 d=3]
59 > (yall 0)
60 [y=0 m=1 d=1]
61```
64---
65### `++yawn`
67Days since beginning of time
69Inverse of `yall`, computes number of days A.D. from y/m/d date as the
70tuple `[yer=@ud mot=@ud day=@ud]`.
72#### Accepts
74`yer` is an unsigned decimal.
76`mon` is an unsigned decimal.
78`day` is an unsigned decimal.
80#### Produces
82An unsigned decimal.
84#### Source
86```hoon
87 ++ yawn
88 |= [yer=@ud mot=@ud day=@ud]
89 ^- @ud
90 => .(mot (dec mot), day (dec day))
91 => ^+ .
92 %= .
93 day
94 =+ cah=?:((yelp yer) moy:yo moh:yo)
95 |- ^- @ud
96 ?: =(0 mot)
97 day
98 $(mot (dec mot), cah (slag 1 cah), day (add day (snag 0 cah)))
99 ==
100 |- ^- @ud
101 ?. =(0 (mod yer 4))
102 =+ ney=(dec yer)
103 $(yer ney, day (add day ?:((yelp ney) 366 365)))
104 ?. =(0 (mod yer 100))
105 =+ nef=(sub yer 4)
106 $(yer nef, day (add day ?:((yelp nef) 1.461 1.460)))
107 ?. =(0 (mod yer 400))
108 =+ nec=(sub yer 100)
109 $(yer nec, day (add day ?:((yelp nec) 36.525 36.524)))
110 (add day (mul (div yer 400) (add 1 (mul 4 36.524))))
111```
113#### Examples
115```
116 > (yawn 2.018 7 4)
117 737.244
119 > (yawn 1.776 7 4)
120 648.856
122 > (yawn 1.990 10 11)
123 727.116
124```
126---
127### `++year`
129Date to @d
131Accept a parsed date of form `[[a=? y=@ud] m=@ud t=tarp]` and produce
132its `@d` representation.
134#### Accepts
136`det` is a `date`
138#### Produces
140A `@d`.
142#### Source
144```hoon
145 ++ year
146 |= det=date
147 ^- @da
148 =+ ^= yer
149 ?: a.det
150 (add 292.277.024.400 y.det)
151 (sub 292.277.024.400 (dec y.det))
152 =+ day=(yawn yer m.det d.t.det)
153 (yule day h.t.det m.t.det s.t.det f.t.det)
154```
156#### Examples
158```
159 > (year [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=4 s=57 f=~[0xd940]]])
160 0x8000000d227df4e9d940000000000000
161```
163---
164### `++yell`
166Tarp from atomic date
168Produce a parsed daily time format from, `@d`, an atomic date.
170#### Accepts
172`now` is a `@d`.
174#### Produces
176A `tarp`.
178#### Source
180```hoon
181 ++ yell
182 |= now=@d
183 ^- tarp
184 =+ sec=(rsh 6 1 now)
185 =+ ^= fan
186 =+ [muc=4 raw=(end 6 1 now)]
187 |- ^- (list @ux)
188 ?: |(=(0 raw) =(0 muc))
189 ~
190 => .(muc (dec muc))
191 [(cut 4 [muc 1] raw) $(raw (end 4 muc raw))]
192 =+ day=(div sec day:yo)
193 => .(sec (mod sec day:yo))
194 =+ hor=(div sec hor:yo)
195 => .(sec (mod sec hor:yo))
196 =+ mit=(div sec mit:yo)
197 => .(sec (mod sec mit:yo))
198 [day hor mit sec fan]
199```
201#### Examples
203```
204 > (yell ~2014.3.20..05.42.53..7456)
205 [d=106.751.991.820.094 h=5 m=42 s=53 f=~[0x7456]]
207 > (yell ~2014.6.9..19.09.40..8b66)
208 [d=106.751.991.820.175 h=19 m=9 s=40 f=~[0x8b66]]
210 > (yell ~1776.7.4)
211 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
212```
214---
215### `++yelp`
217Leap-week?
219Determines whether a year contains an ISO 8601 leap-week. Produces a flag.
221#### Accepts
223`yer` is an unsigned decimal.
225#### Produces
227A flag.
229#### Source
231```hoon
232 ++ yelp
233 |= yer=@ud ^- ?
234 &(=(0 (mod yer 4)) |(!=(0 (mod yer 100)) =(0 (mod yer 400))))
235```
237#### Examples
239```
240 > (yelp 2.014)
241 %.n
243 > (yelp 2.008)
244 %.y
246 > (yelp 0)
247 %.y
249 > (yelp 14.011)
250 %.n
251```
253---
254### `++yore`
256Date from atomic date
258Produces a `date` from a `@d`.
260#### Accepts
262`now` is a time atom, `@d`.
264#### Produces
266A `date`.
268#### Source
270```hoon
271 ++ yore
272 |= now=@da
273 ^- date
274 =+ rip=(yell now)
275 =+ ger=(yall d.rip)
276 :- ?: (gth y.ger 292.277.024.400)
277 [a=& y=(sub y.ger 292.277.024.400)]
278 [a=| y=+((sub 292.277.024.400 y.ger))]
279 [m.ger d.ger h.rip m.rip s.rip f.rip]
280```
282#### Examples
284```
285 > (yore ~2014.6.6..21.09.15..0a16)
286 [[a=%.y y=2.014] m=6 t=[d=6 h=21 m=9 s=15 f=~[0xa16]]]
287```
289---
290### `++yule`
292Daily time to time atom
294Accepts a `tarp`, a parsed daily time, and produces a time atom,
295`@d`.
297#### Accepts
299`rip` is a `tarp`.
301#### Produces
303A time atom, `@d`.
305#### Source
307```hoon
308 ++ yule :: time atom
309 |= rip=tarp
310 ^- @d
311 =+ ^= sec ;: add
312 (mul d.rip day:yo)
313 (mul h.rip hor:yo)
314 (mul m.rip mit:yo)
315 s.rip
316 ==
317 =+ ^= fac =+ muc=4
318 |- ^- @
319 ?~ f.rip
320 0
321 => .(muc (dec muc))
322 (add (lsh 4 muc i.f.rip) $(f.rip t.f.rip))
323 (con (lsh 6 1 sec) fac)
324 ::
325```
327#### Examples
329```
330 > =murica (yell ~1776.7.4)
332 > murica
333 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
335 > (yule murica)
336 0x8000000b62aaf5800000000000000000
338 > `@da`(yule murica)
339 ~1776.7.4
341 > `@da`(yule (yell ~2014.3.20..05.42.53..7456))
342 ~2014.3.20..05.42.53..7456
344 > `tarp`[31 12 30 0 ~]
345 [d=31 h=12 m=30 s=0 f=~]
347 > `@dr`(yule `tarp`[31 12 30 0 ~])
348 ~d31.h12.m30
349```
351---
352### `++yo`
354Time constants core
356Core whose arms contain constants for interacting with earth time.
358#### Source
360```hoon
361 ++ yo
362```
364---
365### `++cet:yo`
367Days in a century
369Derived by multiplying the number of days in a year
370(365) by the number of years in a century (100), then adding the number
371days from leap-years in a century (24).
373#### Produces
375An atom.
377#### Source
379```hoon
380 |% ++ cet 36.524
381```
383#### Examples
385```
386 > cet:yo
387 36.524
389 > (add 365 cet:yo)
390 36.889
392 > (sub (add 24 (mul 100 365)) cet:yo)
393 0
394```
396---
397### `++day:yo`
399Seconds in day
401The number of seconds in a day.
403#### Produces
405An atom.
407#### Source
409```hoon
410 ++ day 86.400
411```
413#### Examples
415```
416 > day:yo
417 86.400
419 > (add 60 day:yo)
420 86.460
421```
423---
424### `++era:yo`
426Leap-year period
428The number of days in a 400-year period, arrived at by multiplying `cet` by four
429and adding one. This is done because every 400 years, there is a leap-year where
430there would otherwise not be.
432#### Produces
434An atom.
436#### Source
438```hoon
439 ++ era 146.097
440```
442#### Examples
444```
445 > era:yo
446 146.097
448 > (sub era:yo (mul 4 cet:yo))
449 1
450```
452#### Discussion
454A year is a leap-year if:
456- it's divisible by 4;
457- **unless** it's divisible by 100;
458- **or** if it's divisible by 400.
460---
461### `++hor:yo`
463Seconds in hour
465The number of seconds in an hour. Derived by multiplying the number of
466seconds in a minute by the minutes in an hour.
468#### Produces
470An atom.
472#### Source
474```hoon
475 ++ hor 3.600
476```
478#### Examples
480```
481 > hor:yo
482 3.600
484 > (div hor:yo 60)
485 60
486```
488---
489### `++jes:yo`
491Maximum 64-bit timestamp
493This is the number of days (starting from 1970) that can be represented in a
49464-bit timestamp. Derived by multiplying `era:yo` by 730,692,561.
496#### Produces
498An atom.
500#### Source
502```hoon
503 ++ jes 106.751.991.084.417
504```
506#### Examples
508```
509 > jes:yo
510 106.751.991.084.417
511```
513#### Discussion
515The date is December 4, 292,277,026,596.
517---
518### `++mit:yo`
520Seconds in minute
522The number of seconds in a minute.
524#### Produces
526An atom.
528#### Source
530```hoon
531 ++ mit 60
532```
534#### Examples
536```
537 > mit:yo
538 60
539```
541---
542### `++moh:yo`
544Days in month
546The days in each month of the Gregorian common year. A list of unsigned
547decimal atoms (Either 28, 30, or 31) denoting the number of days in the
548month at the year at that index.
550#### Produces
552A `list` of `@ud`
554#### Source
556```hoon
557 ++ moh `(list @ud)`[31 28 31 30 31 30 31 31 30 31 30 31 ~]
558```
560#### Examples
562```
563 > moh:yo
564 ~[31 28 31 30 31 30 31 31 30 31 30 31]
566 > (snag 4 moh:yo)
567 31
568```
570---
571### `++moy:yo`
573Days in months of leap-year
575The days in each month of the Gregorian leap-year. A list of unsigned
576decimal atoms (Either 29, 30, or 31) denoting the number of days in the
577month at the leap-year at that index.
579#### Produces
581A `list` of `@ud`.
583#### Source
585```hoon
586 ++ moy `(list @ud)`[31 29 31 30 31 30 31 31 30 31 30 31 ~]
587```
589#### Examples
591```
592 > moy:yo
593 ~[31 29 31 30 31 30 31 31 30 31 30 31]
595 > (snag 1 moy:yo)
596 29
597```
599---
600### `++qad:yo`
602Seconds in 4 years
604The number of seconds in four years. Derived by adding one second to the
605number of seconds in four years.
607#### Produces
609An atom.
611#### Source
613```hoon
614 ++ qad 126.144.001
615```
617#### Examples
619```
620 > qad:yo
621 126.144.001
622```
624---
625### `++yer:yo`
627Seconds in year
629The number of seconds in a year. Derived by multiplying the number of
630seconds in a day by 365.
632#### Produces
634An atom.
636#### Source
638```hoon
639 ++ yer 31.536.000
640```
642#### Examples
644```
645 > yer:yo
646 31.536.000
647```
649---