on 140ac0e help sign in
595 lines 10 kB history raw
1# 3c: urbit time
2### `++yo`
4 ++ yo :: time constants core
5
6Useful constants for interacting with earth time.
8### `++cet`
10Days in a century. Derived by multiplying the number of days in a year
11(365) by the number of years in a century (100), then adding the number
12days from leap years in a century (24).
14Produces
15--------
17An atom.
19Source
20------
22 |% ++ cet 36.524 :: (add 24 (mul 100 365))
24Examples
25--------
27 > cet:yo
28 36.524
29 > (add 365 cet:yo)
30 36.889
31 > (sub (add 24 (mul 100 365)) cet:yo)
32 0
34------------------------------------------------------------------------
36### `++day`
38Number of seconds in a day.
40Produces
41--------
43An atom.
45Source
46------
48 ++ day 86.400 :: (mul 24 hor)
50Examples
51--------
53 > day:yo
54 86.400
55 > (add 60 day:yo)
56 86.460
58------------------------------------------------------------------------
60### `++era`
62XX Revisit
64Produces
65--------
67An atom.
69Source
70------
72 ++ era 146.097 :: (add 1 (mul 4 cet))
74Examples
75--------
78------------------------------------------------------------------------
80### `++hor`
82Seconds in hour
84The number of seconds in an hour. Derived by multiplying the number of
85seconds in a minute by the minutes in an hour.
87Produces
88--------
90An atom.
92Source
93------
95 ++ hor 3.600 :: (mul 60 mit)
97Examples
98--------
100 > hor:yo
101 3.600
102 > (div hor:yo 60)
103 60
105------------------------------------------------------------------------
107### `++jes`
109XX Revisit
111Produces
112--------
114An atom.
116Source
117------
119 ++ jes 106.751.991.084.417 :: (mul 730.692.561 era)
121Examples
122--------
124 > jes:yo
125 106.751.991.084.417
127------------------------------------------------------------------------
129### `++mit`
131Seconds in minute
133The number of seconds in a minute.
135Produces
136--------
138An atom.
140Source
141------
143 ++ mit 60
145Examples
146--------
148 > mit:yo
149 60
151------------------------------------------------------------------------
153### `++moh`
155Days in month
157The days in each month of the Gregorian common year. A list of unsigned
158decimal atoms (Either 28, 30, or 31) denoting the number of days in the
159month at the year at that index.
161Produces
162--------
164A `++list` of `@ud`
166Source
167------
169 ++ moh `(list @ud)`[31 28 31 30 31 30 31 31 30 31 30 31 ~]
171Examples
172--------
174 > moh:yo
175 ~[31 28 31 30 31 30 31 31 30 31 30 31]
176 > (snag 4 moh:yo)
177 31
179------------------------------------------------------------------------
181### `++moy`
183Moh with leapyear
185The days in each month of the Gregorian leap-year. A list of unsigned
186decimal atoms (Either 29,30, or 31) denoting the number of days in the
187month at the leap-year at that index.
189Examples
190--------
192A `++list` of `@ud`
194Source
195------
197 ++ moy `(list @ud)`[31 29 31 30 31 30 31 31 30 31 30 31 ~]
199Examples
200--------
202 > moy:yo
203 ~[31 29 31 30 31 30 31 31 30 31 30 31]
204 > (snag 1 moy:yo)
205 29
207------------------------------------------------------------------------
209### `++qad`
211Seconds in 4 years
213The number of seconds in four years. Derived by adding one second to the
214number of seconds in four years.
216Produces
217--------
219An atom.
221Source
222------
224 ++ qad 126.144.001 :: (add 1 (mul 4 yer))
226Examples
227--------
229 > qad:yo
230 126.144.001
232------------------------------------------------------------------------
234### `++yer`
236Seconds in year
238The number of seconds in a year. Derived by multiplying the number of
239seconds in a day by 365.
241Produces
242--------
244An atom.
246Source
247------
249 ++ yer 31.536.000 :: (mul 365 day)
251Examples
252--------
254 > yer:yo
255 31.536.000
259***
260### `++yall`
262Time since beginning of time
264Produce the date tuple of `[y=@ud m=@ud d=@ud]` of the year, month, and
265day from a number of days from the beginning of time.
267Accepts
268-------
270`day` is a [`@ud`]()
272Produces
273--------
276Source
277------
279 ++ yall :: day / to day of year
280 |= day/@ud
281 ^- {y/@ud m/@ud d/@ud}
282 =+ [era=0 cet=0 lep=*?]
283 => .(era (div day era:yo), day (mod day era:yo))
284 => ^+ .
285 ?: (lth day +(cet:yo))
286 .(lep &, cet 0)
287 => .(lep |, cet 1, day (sub day +(cet:yo)))
288 .(cet (add cet (div day cet:yo)), day (mod day cet:yo))
289 =+ yer=(add (mul 400 era) (mul 100 cet))
290 |- ^- {y/@ud m/@ud d/@ud}
291 =+ dis=?:(lep 366 365)
292 ?. (lth day dis)
293 =+ ner=+(yer)
294 $(yer ner, day (sub day dis), lep =(0 (end 0 2 ner)))
295 |- ^- {y/@ud m/@ud d/@ud}
296 =+ [mot=0 cah=?:(lep moy:yo moh:yo)]
297 |- ^- {y/@ud m/@ud d/@ud}
298 =+ zis=(snag mot cah)
299 ?: (lth day zis)
300 [yer +(mot) +(day)]
301 $(mot +(mot), day (sub day zis))
302 ::
304Examples
305--------
307 > (yall 198)
308 [y=0 m=7 d=17]
309 > (yall 90.398)
310 [y=247 m=7 d=3]
311 > (yall 0)
312 [y=0 m=1 d=1]
316***
317### `++yawn`
319Days since beginning of time
321Inverse of `yall`, computes number of days A.D. from y/m/d date as the
322tuple `[yer=@ud mot=@ud day=@ud]`.
324Accepts
325-------
327`yer` is an unsigned decimal, `@ud`.
329`mon` is an unsigned decimal, `@ud`.
331`day` is an unsigned decimal, `@ud`.
333Produces
334--------
336A `@ud`.
338Source
339------
341 ++ yawn :: days since Jesus
342 |= {yer/@ud mot/@ud day/@ud}
343 ^- @ud
344 => .(mot (dec mot), day (dec day))
345 => ^+ .
346 %= .
347 day
348 =+ cah=?:((yelp yer) moy:yo moh:yo)
349 |- ^- @ud
350 ?: =(0 mot)
351 day
352 $(mot (dec mot), cah (slag 1 cah), day (add day (snag 0 cah)))
353 ==
354 |- ^- @ud
355 ?. =(0 (mod yer 4))
356 =+ ney=(dec yer)
357 $(yer ney, day (add day ?:((yelp ney) 366 365)))
358 ?. =(0 (mod yer 100))
359 =+ nef=(sub yer 4)
360 $(yer nef, day (add day ?:((yelp nef) 1.461 1.460)))
361 ?. =(0 (mod yer 400))
362 =+ nec=(sub yer 100)
363 $(yer nec, day (add day ?:((yelp nec) 36.525 36.524)))
364 (add day (mul (div yer 400) (add 1 (mul 4 36.524))))
365 ::
367Examples
368--------
370 > (yawn 2.014 8 4)
371 735.814
372 > (yawn 1.776 7 4)
373 648.856
374 > (yawn 1.990 10 11)
375 727.116
379***
380### `++year`
382Accept a parsed date of form `[[a=? y=@ud] m=@ud t=tarp]` and produce
383its `@d`representation.
385Accepts
386-------
388`det` is a `++date`
390Produces
391--------
393A `@d`.
395Source
396------
398 ++ year :: date to @d
399 |= det/date
400 ^- @da
401 =+ ^= yer
402 ?: a.det
403 (add 292.277.024.400 y.det)
404 (sub 292.277.024.400 (dec y.det))
405 =+ day=(yawn yer m.det d.t.det)
406 (yule day h.t.det m.t.det s.t.det f.t.det)
407 ::
409Examples
410--------
412 > (year [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=4 s=57 f=~[0xd940]]])
413 0x8000000d227df4e9d940000000000000
417***
418### `++yell`
420Produce a parsed daily time format from an atomic date.
422`now` is a `@d`.
424Source
425------
427 ++ yell :: tarp from @d
428 |= now/@d
429 ^- tarp
430 =+ sec=(rsh 6 1 now)
431 =+ ^= fan
432 =+ [muc=4 raw=(end 6 1 now)]
433 |- ^- (list @ux)
434 ?: |(=(0 raw) =(0 muc))
435 ~
436 => .(muc (dec muc))
437 [(cut 4 [muc 1] raw) $(raw (end 4 muc raw))]
438 =+ day=(div sec day:yo)
439 => .(sec (mod sec day:yo))
440 =+ hor=(div sec hor:yo)
441 => .(sec (mod sec hor:yo))
442 =+ mit=(div sec mit:yo)
443 => .(sec (mod sec mit:yo))
444 [day hor mit sec fan]
445 ::
448Examples
449--------
451 > (yell ~2014.3.20..05.42.53..7456)
452 [d=106.751.991.820.094 h=5 m=42 s=53 f=~[0x7456]]
453 > (yell ~2014.6.9..19.09.40..8b66)
454 [d=106.751.991.820.175 h=19 m=9 s=40 f=~[0x8b66]]
455 > (yell ~1776.7.4)
456 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
459***
460### `++yelp`
462Leap-week?
464Determines whether a year contains an ISO 8601 leap week. Produces a
465loobean.
467Accepts
468-------
470`yer` is an unsigned decimal, `@ud`.
472Produces
473--------
475A boolean.
477Source
478------
480 ++ yelp :: leap year
481 |= yer=@ud ^- ?
482 &(=(0 (mod yer 4)) |(!=(0 (mod yer 100)) =(0 (mod yer 400))))
484Examples
485--------
487 > (yelp 2.014)
488 %.n
489 > (yelp 2.008)
490 %.y
491 > (yelp 0)
492 %.y
493 > (yelp 14.011)
494 %.n
498***
499### `++yore`
501Produces a `++date` from a `@d`
503Accepts
504-------
506`now` is a `@d`.
508Produces
509--------
511A `++date`.
513Source
514------
516 ++ yore :: @d to date
517 |= now/@da
518 ^- date
519 =+ rip=(yell now)
520 =+ ger=(yall d.rip)
521 :- ?: (gth y.ger 292.277.024.400)
522 [a=& y=(sub y.ger 292.277.024.400)]
523 [a=| y=+((sub 292.277.024.400 y.ger))]
524 [m.ger d.ger h.rip m.rip s.rip f.rip]
525 ::
527Examples
528--------
530 > (yore -<-)
531 [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=17 s=1 f=~[0x700d]]]
532 > (yore -<-)
533 [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=28 s=53 f=~[0x7b82]]]
537***
538### `++yule`
540Daily time to time atom
542Accept a `++tarp`, a parsed daily time, and produces a time atom,
543`@d`.
545Accepts
546-------
548`rip` is a `++tarp`.
550Produces
551--------
553A `@d`.
555Source
556------
558 ++ yule :: time atom
559 |= rip/tarp
560 ^- @d
561 =+ ^= sec ;: add
562 (mul d.rip day:yo)
563 (mul h.rip hor:yo)
564 (mul m.rip mit:yo)
565 s.rip
566 ==
567 =+ ^= fac =+ muc=4
568 |- ^- @
569 ?~ f.rip
570 0
571 => .(muc (dec muc))
572 (add (lsh 4 muc i.f.rip) $(f.rip t.f.rip))
573 (con (lsh 6 1 sec) fac)
574 ::
576Examples
577--------
579 > =murica (yell ~1776.7.4)
580 > murica
581 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
582 > (yule murica)
583 0x8000000b62aaf5800000000000000000
584 > `@da`(yule murica)
585 ~1776.7.4
586 > `@da`(yule (yell ~2014.3.20..05.42.53..7456))
587 ~2014.3.20..05.42.53..7456
588 > `tarp`[31 12 30 0 ~]
589 [d=31 h=12 m=30 s=0 f=~]
590 > `@dr`(yule `tarp`[31 12 30 0 ~])
591 ~d31.h12.m30
595***