~/bend-docscommunity

src/clock.bend checks

raw source on the hub · import ezsys@0.2.0.0/src/clock.bend as Clock

ezsys/src/clock: Unix time as ISO 8601 UTC, YYYY-MM-DDTHH:MM:SS.mmmZ. Pure: the wall clock itself is the effect in src/sys.bend. The input is whole seconds since 1970-01-01T00:00:00Z as a U32, which reaches 2106-02-07T06:28:15Z, and the milliseconds past that second.

The date is Howard Hinnant's civil_from_days (https://howardhinnant.github.io/date_algorithms.html#civil_from_days), the proleptic Gregorian calendar in 400-year eras of 146097 days, its years starting on 1 March so that the leap day is the last day of a year. Every intermediate value is unsigned and fits in a U32 for every U32 input.

1 import
import Base

Types

type Ymd source · line 14 · raw

Data

a calendar date

type Wd source · line 114 · raw

Data

the days of the week

Definitions

def time.digit.at source · line 18 · raw

@place:Nat -> Char

the k-th decimal digit character (9 for anything past it)

def time.digit source · line 42 · raw

@num:U32 -> Char

the decimal digit of n's last place

def time.civil.month source · line 46 · raw

@+mp:U32 -> U32

the month of a March-based month index (0 is March)

def time.civil.year source · line 51 · raw

@+year:U32 -> @+month:U32 -> U32

the calendar year of a March-based year: January and February are the next calendar year's

def time.civil source · line 55 · raw

@days:U32 -> Ymd

the year, month and day of a day number (days since 1970-01-01)

def time.two source · line 67 · raw

@+num:U32 -> String

two decimal places: tens and units

def time.three source · line 71 · raw

@+num:U32 -> String

three decimal places: hundreds, tens and units

def time.four source · line 76 · raw

@+num:U32 -> String

four decimal places: thousands, hundreds, tens and units

def time.ymd source · line 81 · raw

@year:U32 -> @month:U32 -> @day:U32 -> String

YYYY-MM-DD

def time.ymd.of source · line 85 · raw

@date:Ymd -> String

the date of a calendar date

def time.date source · line 91 · raw

@days:U32 -> String

YYYY-MM-DD of a day number

def time.clock source · line 96 · raw

@+sod:U32 -> @ms:U32 -> String

HH:MM:SS.mmmZ of a second of the day and a millisecond (its last three decimal places)

def time.iso source · line 102 · raw

@+secs:U32 -> @ms:U32 -> String

ISO 8601 UTC of seconds since the epoch and a millisecond

def time.iso.of source · line 107 · raw

@now:Pair(U32, U32) -> String

ISO 8601 UTC of a clock reading: seconds and milliseconds

def time.wd.next source · line 124 · raw

@day:Wd -> Wd

the next day of the week: Sunday is followed by Monday

def time.wd.num source · line 142 · raw

@day:Wd -> U32

the ISO 8601 weekday number of a day of the week: 1 Monday to 7 Sunday

def time.wd.go source · line 160 · raw

@left:Nat -> @day:Wd -> Wd

the day of the week left days after day, one day at a time

def time.weekday.nat source · line 170 · raw

@num:Nat -> U32

the ISO weekday of day num after 1970-01-01, a Thursday, counted one day at a time: the weekday's definition, which time.weekday computes faster

def time.wd.plus source · line 175 · raw

@day:Wd -> @off:Wd -> Wd

two weekdays added as offsets from Monday (Monday is 0, Sunday 6), so time.wd.plus(day, off) is the weekday off days after day

def time.wd.bits source · line 278 · raw

@len:Nat -> @word:Word(len) -> Wd

the day of the week a word's value in days after a Monday, one bit at a time from the lowest: the value is the bit plus twice the rest's

def time.weekday source · line 292 · raw

@days:U32 -> U32

the ISO weekday of a day number, in 32 steps, one a bit

def time.jan1 source · line 299 · raw

@year:U32 -> U32

the day number of 1 January of a year from 1970 on: Howard Hinnant's days_from_civil for month 1, day 1

def time.thursday source · line 306 · raw

@+days:U32 -> U32

the Thursday of a day's ISO week (Monday to Sunday)

def time.week.of source · line 311 · raw

@+thu:U32 -> @date:Ymd -> Pair(U32, U32)

the ISO year and week of a week's Thursday: the Thursday's calendar year, and how many Thursdays of that year it is

def time.week source · line 317 · raw

@+days:U32 -> Pair(U32, U32)

the ISO 8601 week-numbering year and week of a day number

def time.iso_week source · line 322 · raw

@+secs:U32 -> Pair(U32, U32)

the ISO 8601 week-numbering year and week of seconds since the epoch

def time.week.text source · line 326 · raw

@week:Pair(U32, U32) -> String

YYYY-Www of an ISO year and week, as date +%G-W%V writes it

def time.iso_week_text source · line 331 · raw

@+secs:U32 -> String

YYYY-Www of seconds since the epoch

def time.fields.of source · line 335 · raw

@date:Ymd -> @+sod:U32 -> @wd:U32 -> Pair(U32, Pair(U32, Pair(U32, Pair(U32, Pair(U32, Pair(U32, U32))))))

a date, a second of the day and a weekday as the civil fields

def time.fields source · line 347 · raw

@+secs:U32 -> Pair(U32, Pair(U32, Pair(U32, Pair(U32, Pair(U32, Pair(U32, U32))))))

year, month, day, hour, minute, second and ISO weekday of seconds since the epoch, in UTC