on 6d45ede help sign in
600 lines 10 kB history raw
1---
2navhome: /docs
3---
6# 3c: urbit time
7### `++yo`
9 ++ yo :: time constants core
11Useful constants for interacting with earth time.
13### `++cet`
15Days in a century. Derived by multiplying the number of days in a year
16(365) by the number of years in a century (100), then adding the number
17days from leap years in a century (24).
19Produces
20--------
22An atom.
24Source
25------
27 |% ++ cet 36.524 :: (add 24 (mul 100 365))
29Examples
30--------
32 > cet:yo
33 36.524
34 > (add 365 cet:yo)
35 36.889
36 > (sub (add 24 (mul 100 365)) cet:yo)
37 0
39------------------------------------------------------------------------
41### `++day`
43Number of seconds in a day.
45Produces
46--------
48An atom.
50Source
51------
53 ++ day 86.400 :: (mul 24 hor)
55Examples
56--------
58 > day:yo
59 86.400
60 > (add 60 day:yo)
61 86.460
63------------------------------------------------------------------------
65### `++era`
67XX Revisit
69Produces
70--------
72An atom.
74Source
75------
77 ++ era 146.097 :: (add 1 (mul 4 cet))
79Examples
80--------
83------------------------------------------------------------------------
85### `++hor`
87Seconds in hour
89The number of seconds in an hour. Derived by multiplying the number of
90seconds in a minute by the minutes in an hour.
92Produces
93--------
95An atom.
97Source
98------
100 ++ hor 3.600 :: (mul 60 mit)
102Examples
103--------
105 > hor:yo
106 3.600
107 > (div hor:yo 60)
108 60
110------------------------------------------------------------------------
112### `++jes`
114XX Revisit
116Produces
117--------
119An atom.
121Source
122------
124 ++ jes 106.751.991.084.417 :: (mul 730.692.561 era)
126Examples
127--------
129 > jes:yo
130 106.751.991.084.417
132------------------------------------------------------------------------
134### `++mit`
136Seconds in minute
138The number of seconds in a minute.
140Produces
141--------
143An atom.
145Source
146------
148 ++ mit 60
150Examples
151--------
153 > mit:yo
154 60
156------------------------------------------------------------------------
158### `++moh`
160Days in month
162The days in each month of the Gregorian common year. A list of unsigned
163decimal atoms (Either 28, 30, or 31) denoting the number of days in the
164month at the year at that index.
166Produces
167--------
169A `++list` of `@ud`
171Source
172------
174 ++ moh `(list @ud)`[31 28 31 30 31 30 31 31 30 31 30 31 ~]
176Examples
177--------
179 > moh:yo
180 ~[31 28 31 30 31 30 31 31 30 31 30 31]
181 > (snag 4 moh:yo)
182 31
184------------------------------------------------------------------------
186### `++moy`
188Moh with leapyear
190The days in each month of the Gregorian leap-year. A list of unsigned
191decimal atoms (Either 29,30, or 31) denoting the number of days in the
192month at the leap-year at that index.
194Examples
195--------
197A `++list` of `@ud`
199Source
200------
202 ++ moy `(list @ud)`[31 29 31 30 31 30 31 31 30 31 30 31 ~]
204Examples
205--------
207 > moy:yo
208 ~[31 29 31 30 31 30 31 31 30 31 30 31]
209 > (snag 1 moy:yo)
210 29
212------------------------------------------------------------------------
214### `++qad`
216Seconds in 4 years
218The number of seconds in four years. Derived by adding one second to the
219number of seconds in four years.
221Produces
222--------
224An atom.
226Source
227------
229 ++ qad 126.144.001 :: (add 1 (mul 4 yer))
231Examples
232--------
234 > qad:yo
235 126.144.001
237------------------------------------------------------------------------
239### `++yer`
241Seconds in year
243The number of seconds in a year. Derived by multiplying the number of
244seconds in a day by 365.
246Produces
247--------
249An atom.
251Source
252------
254 ++ yer 31.536.000 :: (mul 365 day)
256Examples
257--------
259 > yer:yo
260 31.536.000
264***
265### `++yall`
267Time since beginning of time
269Produce the date tuple of `[y=@ud m=@ud d=@ud]` of the year, month, and
270day from a number of days from the beginning of time.
272Accepts
273-------
275`day` is a [`@ud`]()
277Produces
278--------
281Source
282------
284 ++ yall :: day / to day of year
285 |= day/@ud
286 ^- {y/@ud m/@ud d/@ud}
287 =+ [era=0 cet=0 lep=*?]
288 => .(era (div day era:yo), day (mod day era:yo))
289 => ^+ .
290 ?: (lth day +(cet:yo))
291 .(lep &, cet 0)
292 => .(lep |, cet 1, day (sub day +(cet:yo)))
293 .(cet (add cet (div day cet:yo)), day (mod day cet:yo))
294 =+ yer=(add (mul 400 era) (mul 100 cet))
295 |- ^- {y/@ud m/@ud d/@ud}
296 =+ dis=?:(lep 366 365)
297 ?. (lth day dis)
298 =+ ner=+(yer)
299 $(yer ner, day (sub day dis), lep =(0 (end 0 2 ner)))
300 |- ^- {y/@ud m/@ud d/@ud}
301 =+ [mot=0 cah=?:(lep moy:yo moh:yo)]
302 |- ^- {y/@ud m/@ud d/@ud}
303 =+ zis=(snag mot cah)
304 ?: (lth day zis)
305 [yer +(mot) +(day)]
306 $(mot +(mot), day (sub day zis))
307 ::
309Examples
310--------
312 > (yall 198)
313 [y=0 m=7 d=17]
314 > (yall 90.398)
315 [y=247 m=7 d=3]
316 > (yall 0)
317 [y=0 m=1 d=1]
321***
322### `++yawn`
324Days since beginning of time
326Inverse of `yall`, computes number of days A.D. from y/m/d date as the
327tuple `[yer=@ud mot=@ud day=@ud]`.
329Accepts
330-------
332`yer` is an unsigned decimal, `@ud`.
334`mon` is an unsigned decimal, `@ud`.
336`day` is an unsigned decimal, `@ud`.
338Produces
339--------
341A `@ud`.
343Source
344------
346 ++ yawn :: days since Jesus
347 |= {yer/@ud mot/@ud day/@ud}
348 ^- @ud
349 => .(mot (dec mot), day (dec day))
350 => ^+ .
351 %= .
352 day
353 =+ cah=?:((yelp yer) moy:yo moh:yo)
354 |- ^- @ud
355 ?: =(0 mot)
356 day
357 $(mot (dec mot), cah (slag 1 cah), day (add day (snag 0 cah)))
358 ==
359 |- ^- @ud
360 ?. =(0 (mod yer 4))
361 =+ ney=(dec yer)
362 $(yer ney, day (add day ?:((yelp ney) 366 365)))
363 ?. =(0 (mod yer 100))
364 =+ nef=(sub yer 4)
365 $(yer nef, day (add day ?:((yelp nef) 1.461 1.460)))
366 ?. =(0 (mod yer 400))
367 =+ nec=(sub yer 100)
368 $(yer nec, day (add day ?:((yelp nec) 36.525 36.524)))
369 (add day (mul (div yer 400) (add 1 (mul 4 36.524))))
370 ::
372Examples
373--------
375 > (yawn 2.014 8 4)
376 735.814
377 > (yawn 1.776 7 4)
378 648.856
379 > (yawn 1.990 10 11)
380 727.116
384***
385### `++year`
387Accept a parsed date of form `[[a=? y=@ud] m=@ud t=tarp]` and produce
388its `@d`representation.
390Accepts
391-------
393`det` is a `++date`
395Produces
396--------
398A `@d`.
400Source
401------
403 ++ year :: date to @d
404 |= det/date
405 ^- @da
406 =+ ^= yer
407 ?: a.det
408 (add 292.277.024.400 y.det)
409 (sub 292.277.024.400 (dec y.det))
410 =+ day=(yawn yer m.det d.t.det)
411 (yule day h.t.det m.t.det s.t.det f.t.det)
412 ::
414Examples
415--------
417 > (year [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=4 s=57 f=~[0xd940]]])
418 0x8000000d227df4e9d940000000000000
422***
423### `++yell`
425Produce a parsed daily time format from an atomic date.
427`now` is a `@d`.
429Source
430------
432 ++ yell :: tarp from @d
433 |= now/@d
434 ^- tarp
435 =+ sec=(rsh 6 1 now)
436 =+ ^= fan
437 =+ [muc=4 raw=(end 6 1 now)]
438 |- ^- (list @ux)
439 ?: |(=(0 raw) =(0 muc))
440 ~
441 => .(muc (dec muc))
442 [(cut 4 [muc 1] raw) $(raw (end 4 muc raw))]
443 =+ day=(div sec day:yo)
444 => .(sec (mod sec day:yo))
445 =+ hor=(div sec hor:yo)
446 => .(sec (mod sec hor:yo))
447 =+ mit=(div sec mit:yo)
448 => .(sec (mod sec mit:yo))
449 [day hor mit sec fan]
450 ::
453Examples
454--------
456 > (yell ~2014.3.20..05.42.53..7456)
457 [d=106.751.991.820.094 h=5 m=42 s=53 f=~[0x7456]]
458 > (yell ~2014.6.9..19.09.40..8b66)
459 [d=106.751.991.820.175 h=19 m=9 s=40 f=~[0x8b66]]
460 > (yell ~1776.7.4)
461 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
464***
465### `++yelp`
467Leap-week?
469Determines whether a year contains an ISO 8601 leap week. Produces a
470loobean.
472Accepts
473-------
475`yer` is an unsigned decimal, `@ud`.
477Produces
478--------
480A boolean.
482Source
483------
485 ++ yelp :: leap year
486 |= yer=@ud ^- ?
487 &(=(0 (mod yer 4)) |(!=(0 (mod yer 100)) =(0 (mod yer 400))))
489Examples
490--------
492 > (yelp 2.014)
493 %.n
494 > (yelp 2.008)
495 %.y
496 > (yelp 0)
497 %.y
498 > (yelp 14.011)
499 %.n
503***
504### `++yore`
506Produces a `++date` from a `@d`
508Accepts
509-------
511`now` is a `@d`.
513Produces
514--------
516A `++date`.
518Source
519------
521 ++ yore :: @d to date
522 |= now/@da
523 ^- date
524 =+ rip=(yell now)
525 =+ ger=(yall d.rip)
526 :- ?: (gth y.ger 292.277.024.400)
527 [a=& y=(sub y.ger 292.277.024.400)]
528 [a=| y=+((sub 292.277.024.400 y.ger))]
529 [m.ger d.ger h.rip m.rip s.rip f.rip]
530 ::
532Examples
533--------
535 > (yore -<-)
536 [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=17 s=1 f=~[0x700d]]]
537 > (yore -<-)
538 [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=28 s=53 f=~[0x7b82]]]
542***
543### `++yule`
545Daily time to time atom
547Accept a `++tarp`, a parsed daily time, and produces a time atom,
548`@d`.
550Accepts
551-------
553`rip` is a `++tarp`.
555Produces
556--------
558A `@d`.
560Source
561------
563 ++ yule :: time atom
564 |= rip/tarp
565 ^- @d
566 =+ ^= sec ;: add
567 (mul d.rip day:yo)
568 (mul h.rip hor:yo)
569 (mul m.rip mit:yo)
570 s.rip
571 ==
572 =+ ^= fac =+ muc=4
573 |- ^- @
574 ?~ f.rip
575 0
576 => .(muc (dec muc))
577 (add (lsh 4 muc i.f.rip) $(f.rip t.f.rip))
578 (con (lsh 6 1 sec) fac)
579 ::
581Examples
582--------
584 > =murica (yell ~1776.7.4)
585 > murica
586 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
587 > (yule murica)
588 0x8000000b62aaf5800000000000000000
589 > `@da`(yule murica)
590 ~1776.7.4
591 > `@da`(yule (yell ~2014.3.20..05.42.53..7456))
592 ~2014.3.20..05.42.53..7456
593 > `tarp`[31 12 30 0 ~]
594 [d=31 h=12 m=30 s=0 f=~]
595 > `@dr`(yule `tarp`[31 12 30 0 ~])
596 ~d31.h12.m30
600***