The Misty Programming Language provides features for dealing with time.
use time
Misty provides three representations of time.
The Misty epoch (or timezero) is "0000-01-01
00:00:00.00 +0000"
, aka January 1 of the year 0. The year
0 was (or would have been) a leap year.
The Unix epoch is "1970-01-01
00:00:00.00 +0000"
, or 62_167_219_200
seconds after the Misty epoch.
time
recordThe time
record contains constants that can be used
when doing time calculations, and methods for converting between representations
of time.
time
constantstime.second : 1
The number of seconds in a second.
time.minute : 60
The number of seconds in a minute.
time.hour : 3_600
The number of seconds in an hour of 60 minutes.
time.day : 86_400
The number of seconds in a day of 24 hours.
time.week : 604_800
The number of seconds in a week of 7 days.
time.month : 2_629_746
The number of seconds in a Gregorian month of 30.436875 days.
time.year : 31_556_952
The number of seconds in a Gregorian year of 365.2425 days
time
functionsThe time
record contains 3 functions: time.number
, time.text
, time.record
.
These inputs are recognized by the time
functions:
inputs ... | interpretation |
---|---|
( number) |
The number of seconds since the epoch. |
( text, format,
zone) |
A date text in one of several formats. |
( record) |
A record containing any of these fields: year , month , day , seventh , hour ,
minute , second , zone . A missing property is assumed to be zero. |
Numbers can be convenient representations of times. my_date + time.day
is the same time tomorrow. Subtraction can be used to determine the difference
between two times in seconds.
A text can contain a textual representation of a time, such as
"2001-09-11"
or "09/11/01"
or
"13:30:00"
.
A format is a text or record that determines how to interpret the text.
A zone is a numeric indication of the local time zone which is indicated by the date text. For example, if the time in the text is local to California (Pacific Standard Time), then zone will be -8.
A record can be used to specify a time. Each of the fields will be relative
to zero (even month and day which are conventionally shown relative to 1). So time.number({year:
2001, month: 8, day: 10})
has the same result as time.number("2001-09-11")
.
The name of the function indicates the type of the result.
,
format,
zone)
)
The result is the number of seconds since the epoch.
time.text(
number,
format,
zone)
,
format,
zone)
The result is a display text of the date. The value cannot be a text.
The format is either a format text or a format record. A format text contains instructions for formatting the date text.
Symbol | to text | from text | |
---|---|---|---|
year | yyyyy |
The year will be displayed in a 5 digit field with zero fill. If
the year is negative and if there is no c or b
in the format, then a leading minus sign will be included. |
Up to 5 digits and an optional leading minus sign. |
yyyy |
The year will be displayed in a 4 digit field with zero fill. If
the year is negative and if there is no c or b
in the format, then a leading minus sign will be included. |
Up to 4 digits and an optional leading minus sign. | |
yy |
modulo(year, 100) will be displayed in a 2 digit field
with zero fill. Not recommended. |
Up to 2 digits and an optional leading minus sign. The current century will be added. Not recommended. | |
y |
The year will be displayed with as many digits as necessary with no fill. If the year is negative and if there
is no c or b in the format, then a leading
minus sign will be included. |
Same as yyyyy . |
|
month | mm |
The number of the month (1-12) in a 2 digit field with zero-fill. | Up to 2 digits. |
m |
The month (1-12). | ||
day of the year | eee |
The day of the year (1-366) in a 3 digit field with zero-fill. | Up to 3 digits. |
day of the month | dd |
The day of the month (1-31) in a 2 digit field with zero-fill. | Up to 2 digits. |
d |
The day of the month (1-31) | ||
day of the week | v |
The day of the week (0-6). | One digit. |
ce/bce | c |
If the year is negative, BCE . If the year is positive,
CE . |
CE or BCE or nothing. |
b |
If the year is negative, BCE . If the year is positive,
nothing. |
||
hours (24) | hh |
The hour (0-23) in a 2 digit field with zero-fill. | Up to 2 digits. |
h |
The hour (0-23). | ||
minutes | nn |
The minute (0-59) in a 2 digit field with zero-fill. | Up to 2 digits. |
n |
The minute (0-59). | ||
seconds | ss |
The second (0-59) in a 2 digit field with zero-fill. | Up to 2 digits. |
s |
The second (0-59). | ||
fraction | ff |
The number of f s determine the number of
digits of fraction of seconds to show. |
Two digits |
f |
One digit | ||
am/pm | a |
If the hour is 13 or more, subtract 12 from the hour and PM . If the hour is 12, then PM . If the hour is 0, make the hour 12 and AM . Otherwise, AM . |
AM or PM or nothing. If PM , if hour is not 12 then add 12 to hour. If AM or nothing, if hour is 12, set hour to 0. |
zone | z |
The time zone, -12 to +11 | -12 to +11 or nothing |
separator | t |
T |
T or space. |
- | - | - or space. |
|
: |
: |
: or space. |
|
/ | / | / or space. |
|
space | space. | space. |
time.record(
number)
time.record(
text,
format,
zone)
The result is a record containing all of these fields: year
,
month
, week
, day_of_year
, day
(of month), day_of_week
, hour
, minute
,
second
. All will have number values. All of the values will
be positive except the year
for dates before the year zero.
All of the fields are relative to zero, including month
and
day
which are conventionally displayed as being relative to 1.
All of the values are integers except for second
which may
have a real value.