on b93c19b help sign in
648 lines 9.9 kB history raw
1+++
2title = "3c: Urbit Time"
3weight = 23
4template = "doc.html"
5+++
6### `++yall`
8Time since beginning of time
10Produce the date tuple of `[y=@ud m=@ud d=@ud]` of the year, month, and
11day from a number of days from the beginning of the Gregorian calendar.
13#### Accepts
15`day` is a an unsigned decimal.
17#### Produces
19A cell of unsigned decimals.
21#### Source
23```
24 ++ yall
25 |= day=@ud
26 ^- [y=@ud m=@ud d=@ud]
27 =+ [era=0 cet=0 lep=*?]
28 => .(era (div day era:yo), day (mod day era:yo))
29 => ^+ .
30 ?: (lth day +(cet:yo))
31 .(lep &, cet 0)
32 => .(lep |, cet 1, day (sub day +(cet:yo)))
33 .(cet (add cet (div day cet:yo)), day (mod day cet:yo))
34 =+ yer=(add (mul 400 era) (mul 100 cet))
35 |- ^- [y=@ud m=@ud d=@ud]
36 =+ dis=?:(lep 366 365)
37 ?. (lth day dis)
38 =+ ner=+(yer)
39 $(yer ner, day (sub day dis), lep =(0 (end 0 2 ner)))
40 |- ^- [y=@ud m=@ud d=@ud]
41 =+ [mot=0 cah=?:(lep moy:yo moh:yo)]
42 |- ^- [y=@ud m=@ud d=@ud]
43 =+ zis=(snag mot cah)
44 ?: (lth day zis)
45 [yer +(mot) +(day)]
46 $(mot +(mot), day (sub day zis))
47```
49#### Examples
51```
52 > (yall 198)
53 [y=0 m=7 d=17]
55 > (yall 90.398)
56 [y=247 m=7 d=3]
58 > (yall 0)
59 [y=0 m=1 d=1]
60```
63---
64### `++yawn`
66Days since beginning of time
68Inverse of `yall`, computes number of days A.D. from y/m/d date as the
69tuple `[yer=@ud mot=@ud day=@ud]`.
71#### Accepts
73`yer` is an unsigned decimal.
75`mon` is an unsigned decimal.
77`day` is an unsigned decimal.
79#### Produces
81An unsigned decimal.
83#### Source
85```
86 ++ yawn
87 |= [yer=@ud mot=@ud day=@ud]
88 ^- @ud
89 => .(mot (dec mot), day (dec day))
90 => ^+ .
91 %= .
92 day
93 =+ cah=?:((yelp yer) moy:yo moh:yo)
94 |- ^- @ud
95 ?: =(0 mot)
96 day
97 $(mot (dec mot), cah (slag 1 cah), day (add day (snag 0 cah)))
98 ==
99 |- ^- @ud
100 ?. =(0 (mod yer 4))
101 =+ ney=(dec yer)
102 $(yer ney, day (add day ?:((yelp ney) 366 365)))
103 ?. =(0 (mod yer 100))
104 =+ nef=(sub yer 4)
105 $(yer nef, day (add day ?:((yelp nef) 1.461 1.460)))
106 ?. =(0 (mod yer 400))
107 =+ nec=(sub yer 100)
108 $(yer nec, day (add day ?:((yelp nec) 36.525 36.524)))
109 (add day (mul (div yer 400) (add 1 (mul 4 36.524))))
110```
112#### Examples
114```
115 > (yawn 2.018 7 4)
116 737.244
118 > (yawn 1.776 7 4)
119 648.856
121 > (yawn 1.990 10 11)
122 727.116
123```
125---
126### `++year`
128Date to @d
130Accept a parsed date of form `[[a=? y=@ud] m=@ud t=tarp]` and produce
131its `@d` representation.
133#### Accepts
135`det` is a `date`
137#### Produces
139A `@d`.
141#### Source
143```
144 ++ year
145 |= det=date
146 ^- @da
147 =+ ^= yer
148 ?: a.det
149 (add 292.277.024.400 y.det)
150 (sub 292.277.024.400 (dec y.det))
151 =+ day=(yawn yer m.det d.t.det)
152 (yule day h.t.det m.t.det s.t.det f.t.det)
153```
155#### Examples
157```
158 > (year [[a=%.y y=2.014] m=8 t=[d=4 h=20 m=4 s=57 f=~[0xd940]]])
159 0x8000000d227df4e9d940000000000000
160```
162---
163### `++yell`
165Tarp from atomic date
167Produce a parsed daily time format from, `@d`, an atomic date.
169#### Accepts
171`now` is a `@d`.
173#### Produces
175A `tarp`.
177#### Source
179```
180 ++ yell
181 |= now=@d
182 ^- tarp
183 =+ sec=(rsh 6 1 now)
184 =+ ^= fan
185 =+ [muc=4 raw=(end 6 1 now)]
186 |- ^- (list @ux)
187 ?: |(=(0 raw) =(0 muc))
188 ~
189 => .(muc (dec muc))
190 [(cut 4 [muc 1] raw) $(raw (end 4 muc raw))]
191 =+ day=(div sec day:yo)
192 => .(sec (mod sec day:yo))
193 =+ hor=(div sec hor:yo)
194 => .(sec (mod sec hor:yo))
195 =+ mit=(div sec mit:yo)
196 => .(sec (mod sec mit:yo))
197 [day hor mit sec fan]
198```
200#### Examples
202```
203 > (yell ~2014.3.20..05.42.53..7456)
204 [d=106.751.991.820.094 h=5 m=42 s=53 f=~[0x7456]]
206 > (yell ~2014.6.9..19.09.40..8b66)
207 [d=106.751.991.820.175 h=19 m=9 s=40 f=~[0x8b66]]
209 > (yell ~1776.7.4)
210 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
211```
213---
214### `++yelp`
216Leap-week?
218Determines whether a year contains an ISO 8601 leap-week. Produces a flag.
220#### Accepts
222`yer` is an unsigned decimal.
224#### Produces
226A flag.
228#### Source
230```
231 ++ yelp
232 |= yer=@ud ^- ?
233 &(=(0 (mod yer 4)) |(!=(0 (mod yer 100)) =(0 (mod yer 400))))
234```
236#### Examples
238```
239 > (yelp 2.014)
240 %.n
242 > (yelp 2.008)
243 %.y
245 > (yelp 0)
246 %.y
248 > (yelp 14.011)
249 %.n
250```
252---
253### `++yore`
255Date from atomic date
257Produces a `date` from a `@d`.
259#### Accepts
261`now` is a time atom, `@d`.
263#### Produces
265A `date`.
267#### Source
269```
270 ++ yore
271 |= now=@da
272 ^- date
273 =+ rip=(yell now)
274 =+ ger=(yall d.rip)
275 :- ?: (gth y.ger 292.277.024.400)
276 [a=& y=(sub y.ger 292.277.024.400)]
277 [a=| y=+((sub 292.277.024.400 y.ger))]
278 [m.ger d.ger h.rip m.rip s.rip f.rip]
279```
281#### Examples
283```
284 > (yore ~2014.6.6..21.09.15..0a16)
285 [[a=%.y y=2.014] m=6 t=[d=6 h=21 m=9 s=15 f=~[0xa16]]]
286```
288---
289### `++yule`
291Daily time to time atom
293Accepts a `tarp`, a parsed daily time, and produces a time atom,
294`@d`.
296#### Accepts
298`rip` is a `tarp`.
300#### Produces
302A time atom, `@d`.
304#### Source
306```
307 ++ yule :: time atom
308 |= rip=tarp
309 ^- @d
310 =+ ^= sec ;: add
311 (mul d.rip day:yo)
312 (mul h.rip hor:yo)
313 (mul m.rip mit:yo)
314 s.rip
315 ==
316 =+ ^= fac =+ muc=4
317 |- ^- @
318 ?~ f.rip
319 0
320 => .(muc (dec muc))
321 (add (lsh 4 muc i.f.rip) $(f.rip t.f.rip))
322 (con (lsh 6 1 sec) fac)
323 ::
324```
326#### Examples
328```
329 > =murica (yell ~1776.7.4)
331 > murica
332 [d=106.751.991.733.273 h=0 m=0 s=0 f=~]
334 > (yule murica)
335 0x8000000b62aaf5800000000000000000
337 > `@da`(yule murica)
338 ~1776.7.4
340 > `@da`(yule (yell ~2014.3.20..05.42.53..7456))
341 ~2014.3.20..05.42.53..7456
343 > `tarp`[31 12 30 0 ~]
344 [d=31 h=12 m=30 s=0 f=~]
346 > `@dr`(yule `tarp`[31 12 30 0 ~])
347 ~d31.h12.m30
348```
350---
351### `++yo`
353Time constants core
355Core whose arms contain constants for interacting with earth time.
357#### Source
359```
360 ++ yo
361```
363---
364### `++cet:yo`
366Days in a century
368Derived by multiplying the number of days in a year
369(365) by the number of years in a century (100), then adding the number
370days from leap-years in a century (24).
372#### Produces
374An atom.
376#### Source
378```
379 |% ++ cet 36.524
380```
382#### Examples
384```
385 > cet:yo
386 36.524
388 > (add 365 cet:yo)
389 36.889
391 > (sub (add 24 (mul 100 365)) cet:yo)
392 0
393```
395---
396### `++day:yo`
398Seconds in day
400The number of seconds in a day.
402#### Produces
404An atom.
406#### Source
408```
409 ++ day 86.400
410```
412#### Examples
414```
415 > day:yo
416 86.400
418 > (add 60 day:yo)
419 86.460
420```
422---
423### `++era:yo`
425Leap-year period
427The number of days in a 400-year period, arrived at by multiplying `cet` by four
428and adding one. This is done because every 400 years, there is a leap-year where
429there would otherwise not be.
431#### Produces
433An atom.
435#### Source
437```
438 ++ era 146.097
439```
441#### Examples
443```
444 > era:yo
445 146.097
447 > (sub era:yo (mul 4 cet:yo))
448 1
449```
451#### Discussion
453A year is a leap-year if:
455- it's divisible by 4;
456- **unless** it's divisible by 100;
457- **or** if it's divisible by 400.
459---
460### `++hor:yo`
462Seconds in hour
464The number of seconds in an hour. Derived by multiplying the number of
465seconds in a minute by the minutes in an hour.
467#### Produces
469An atom.
471#### Source
473```
474 ++ hor 3.600
475```
477#### Examples
479```
480 > hor:yo
481 3.600
483 > (div hor:yo 60)
484 60
485```
487---
488### `++jes:yo`
490Maximum 64-bit timestamp
492This is the number of days (starting from 1970) that can be represented in a
49364-bit timestamp. Derived by multiplying `era:yo` by 730,692,561.
495#### Produces
497An atom.
499#### Source
501```
502 ++ jes 106.751.991.084.417
503```
505#### Examples
507```
508 > jes:yo
509 106.751.991.084.417
510```
512#### Discussion
514The date is December 4, 292,277,026,596.
516---
517### `++mit:yo`
519Seconds in minute
521The number of seconds in a minute.
523#### Produces
525An atom.
527#### Source
529```
530 ++ mit 60
531```
533#### Examples
535```
536 > mit:yo
537 60
538```
540---
541### `++moh:yo`
543Days in month
545The days in each month of the Gregorian common year. A list of unsigned
546decimal atoms (Either 28, 30, or 31) denoting the number of days in the
547month at the year at that index.
549#### Produces
551A `list` of `@ud`
553#### Source
555```
556 ++ moh `(list @ud)`[31 28 31 30 31 30 31 31 30 31 30 31 ~]
557```
559#### Examples
561```
562 > moh:yo
563 ~[31 28 31 30 31 30 31 31 30 31 30 31]
565 > (snag 4 moh:yo)
566 31
567```
569---
570### `++moy:yo`
572Days in months of leap-year
574The days in each month of the Gregorian leap-year. A list of unsigned
575decimal atoms (Either 29, 30, or 31) denoting the number of days in the
576month at the leap-year at that index.
578#### Produces
580A `list` of `@ud`.
582#### Source
584```
585 ++ moy `(list @ud)`[31 29 31 30 31 30 31 31 30 31 30 31 ~]
586```
588#### Examples
590```
591 > moy:yo
592 ~[31 29 31 30 31 30 31 31 30 31 30 31]
594 > (snag 1 moy:yo)
595 29
596```
598---
599### `++qad:yo`
601Seconds in 4 years
603The number of seconds in four years. Derived by adding one second to the
604number of seconds in four years.
606#### Produces
608An atom.
610#### Source
612```
613 ++ qad 126.144.001
614```
616#### Examples
618```
619 > qad:yo
620 126.144.001
621```
623---
624### `++yer:yo`
626Seconds in year
628The number of seconds in a year. Derived by multiplying the number of
629seconds in a day by 365.
631#### Produces
633An atom.
635#### Source
637```
638 ++ yer 31.536.000
639```
641#### Examples
643```
644 > yer:yo
645 31.536.000
646```
648---