on bbd4189 help sign in
665 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```
63---
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---
128## `++year`
130Date to @d
132Accept a parsed date of form `[[a=? y=@ud] m=@ud t=tarp]` and produce
133its `@d` representation.
135#### Accepts
137`det` is a `date`
139#### Produces
141A `@d`.
143#### Source
145```hoon
146 ++ year
147 |= det=date
148 ^- @da
149 =+ ^= yer
150 ?: a.det
151 (add 292.277.024.400 y.det)
152 (sub 292.277.024.400 (dec y.det))
153 =+ day=(yawn yer m.det d.t.det)
154 (yule day h.t.det m.t.det s.t.det f.t.det)
155```
157#### Examples
159```
160 > (year [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=4 s=57 f=~[0xd940]]])
161 0x8000000d227df4e9d940000000000000
162```
164---
166## `++yell`
168Tarp from atomic date
170Produce a parsed daily time format from, `@d`, an atomic date.
172#### Accepts
174`now` is a `@d`.
176#### Produces
178A `tarp`.
180#### Source
182```hoon
183 ++ yell
184 |= now=@d
185 ^- tarp
186 =+ sec=(rsh 6 1 now)
187 =+ ^= fan
188 =+ [muc=4 raw=(end 6 1 now)]
189 |- ^- (list @ux)
190 ?: |(=(0 raw) =(0 muc))
191 ~
192 => .(muc (dec muc))
193 [(cut 4 [muc 1] raw) $(raw (end 4 muc raw))]
194 =+ day=(div sec day:yo)
195 => .(sec (mod sec day:yo))
196 =+ hor=(div sec hor:yo)
197 => .(sec (mod sec hor:yo))
198 =+ mit=(div sec mit:yo)
199 => .(sec (mod sec mit:yo))
200 [day hor mit sec fan]
201```
203#### Examples
205```
206 > (yell ~2014.3.20..05.42.53..7456)
207 [d=106.751.991.820.094 h=5 m=42 s=53 f=~[0x7456]]
209 > (yell ~2014.6.9..19.09.40..8b66)
210 [d=106.751.991.820.175 h=19 m=9 s=40 f=~[0x8b66]]
212 > (yell ~1776.7.4)
213 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
214```
216---
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```hoon
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---
258## `++yore`
260Date from atomic date
262Produces a `date` from a `@d`.
264#### Accepts
266`now` is a time atom, `@d`.
268#### Produces
270A `date`.
272#### Source
274```hoon
275 ++ yore
276 |= now=@da
277 ^- date
278 =+ rip=(yell now)
279 =+ ger=(yall d.rip)
280 :- ?: (gth y.ger 292.277.024.400)
281 [a=& y=(sub y.ger 292.277.024.400)]
282 [a=| y=+((sub 292.277.024.400 y.ger))]
283 [m.ger d.ger h.rip m.rip s.rip f.rip]
284```
286#### Examples
288```
289 > (yore ~2014.6.6..21.09.15..0a16)
290 [[a=%.y y=2.014] m=6 t=[d=6 h=21 m=9 s=15 f=~[0xa16]]]
291```
293---
295## `++yule`
297Daily time to time atom
299Accepts a `tarp`, a parsed daily time, and produces a time atom,
300`@d`.
302#### Accepts
304`rip` is a `tarp`.
306#### Produces
308A time atom, `@d`.
310#### Source
312```hoon
313 ++ yule :: time atom
314 |= rip=tarp
315 ^- @d
316 =+ ^= sec ;: add
317 (mul d.rip day:yo)
318 (mul h.rip hor:yo)
319 (mul m.rip mit:yo)
320 s.rip
321 ==
322 =+ ^= fac =+ muc=4
323 |- ^- @
324 ?~ f.rip
325 0
326 => .(muc (dec muc))
327 (add (lsh 4 muc i.f.rip) $(f.rip t.f.rip))
328 (con (lsh 6 1 sec) fac)
329 ::
330```
332#### Examples
334```
335 > =murica (yell ~1776.7.4)
337 > murica
338 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
340 > (yule murica)
341 0x8000000b62aaf5800000000000000000
343 > `@da`(yule murica)
344 ~1776.7.4
346 > `@da`(yule (yell ~2014.3.20..05.42.53..7456))
347 ~2014.3.20..05.42.53..7456
349 > `tarp`[31 12 30 0 ~]
350 [d=31 h=12 m=30 s=0 f=~]
352 > `@dr`(yule `tarp`[31 12 30 0 ~])
353 ~d31.h12.m30
354```
356---
358## `++yo`
360Time constants core
362Core whose arms contain constants for interacting with earth time.
364#### Source
366```hoon
367 ++ yo
368```
370---
372### `++cet:yo`
374Days in a century
376Derived by multiplying the number of days in a year
377(365) by the number of years in a century (100), then adding the number
378days from leap-years in a century (24).
380#### Produces
382An atom.
384#### Source
386```hoon
387 |% ++ cet 36.524
388```
390#### Examples
392```
393 > cet:yo
394 36.524
396 > (add 365 cet:yo)
397 36.889
399 > (sub (add 24 (mul 100 365)) cet:yo)
400 0
401```
403---
405### `++day:yo`
407Seconds in day
409The number of seconds in a day.
411#### Produces
413An atom.
415#### Source
417```hoon
418 ++ day 86.400
419```
421#### Examples
423```
424 > day:yo
425 86.400
427 > (add 60 day:yo)
428 86.460
429```
431---
433### `++era:yo`
435Leap-year period
437The number of days in a 400-year period, arrived at by multiplying `cet` by four
438and adding one. This is done because every 400 years, there is a leap-year where
439there would otherwise not be.
441#### Produces
443An atom.
445#### Source
447```hoon
448 ++ era 146.097
449```
451#### Examples
453```
454 > era:yo
455 146.097
457 > (sub era:yo (mul 4 cet:yo))
458 1
459```
461#### Discussion
463A year is a leap-year if:
465- it's divisible by 4;
466- **unless** it's divisible by 100;
467- **or** if it's divisible by 400.
469---
471### `++hor:yo`
473Seconds in hour
475The number of seconds in an hour. Derived by multiplying the number of
476seconds in a minute by the minutes in an hour.
478#### Produces
480An atom.
482#### Source
484```hoon
485 ++ hor 3.600
486```
488#### Examples
490```
491 > hor:yo
492 3.600
494 > (div hor:yo 60)
495 60
496```
498---
500### `++jes:yo`
502Maximum 64-bit timestamp
504This is the number of days (starting from 1970) that can be represented in a
50564-bit timestamp. Derived by multiplying `era:yo` by 730,692,561.
507#### Produces
509An atom.
511#### Source
513```hoon
514 ++ jes 106.751.991.084.417
515```
517#### Examples
519```
520 > jes:yo
521 106.751.991.084.417
522```
524#### Discussion
526The date is December 4, 292,277,026,596.
528---
530### `++mit:yo`
532Seconds in minute
534The number of seconds in a minute.
536#### Produces
538An atom.
540#### Source
542```hoon
543 ++ mit 60
544```
546#### Examples
548```
549 > mit:yo
550 60
551```
553---
555### `++moh:yo`
557Days in month
559The days in each month of the Gregorian common year. A list of unsigned
560decimal atoms (Either 28, 30, or 31) denoting the number of days in the
561month at the year at that index.
563#### Produces
565A `list` of `@ud`
567#### Source
569```hoon
570 ++ moh `(list @ud)`[31 28 31 30 31 30 31 31 30 31 30 31 ~]
571```
573#### Examples
575```
576 > moh:yo
577 ~[31 28 31 30 31 30 31 31 30 31 30 31]
579 > (snag 4 moh:yo)
580 31
581```
583---
585### `++moy:yo`
587Days in months of leap-year
589The days in each month of the Gregorian leap-year. A list of unsigned
590decimal atoms (Either 29, 30, or 31) denoting the number of days in the
591month at the leap-year at that index.
593#### Produces
595A `list` of `@ud`.
597#### Source
599```hoon
600 ++ moy `(list @ud)`[31 29 31 30 31 30 31 31 30 31 30 31 ~]
601```
603#### Examples
605```
606 > moy:yo
607 ~[31 29 31 30 31 30 31 31 30 31 30 31]
609 > (snag 1 moy:yo)
610 29
611```
613---
615### `++qad:yo`
617Seconds in 4 years
619The number of seconds in four years. Derived by adding one second to the
620number of seconds in four years.
622#### Produces
624An atom.
626#### Source
628```hoon
629 ++ qad 126.144.001
630```
632#### Examples
634```
635 > qad:yo
636 126.144.001
637```
639---
641### `++yer:yo`
643Seconds in year
645The number of seconds in a year. Derived by multiplying the number of
646seconds in a day by 365.
648#### Produces
650An atom.
652#### Source
654```hoon
655 ++ yer 31.536.000
656```
658#### Examples
660```
661 > yer:yo
662 31.536.000
663```
665---