wtf instant was MEMO: oops. docs
parent
7025ebd7ee
commit
261fc87dca
|
@ -250,6 +250,7 @@ HELP: dt>seconds
|
|||
"360"
|
||||
}
|
||||
} ;
|
||||
|
||||
HELP: dt>milliseconds
|
||||
{ $values { "duration" duration } { "x" number } }
|
||||
{ $description "Calculates the length of a duration in milliseconds." }
|
||||
|
@ -259,3 +260,42 @@ HELP: dt>milliseconds
|
|||
"6000"
|
||||
}
|
||||
} ;
|
||||
|
||||
{ dt>years dt>months dt>days dt>hours dt>minutes dt>seconds dt>milliseconds } related-words
|
||||
|
||||
|
||||
HELP: time-
|
||||
{ $values { "time1" "timestamp or duration" } { "time2" "timestamp or duration" } { "time3" "timestamp or duration" } }
|
||||
{ $description "Subtracts two durations to produce a duration or subtracts a duration from a timestamp to produce a timestamp. The calculation takes timezones into account." }
|
||||
{ $examples
|
||||
{ $example "USING: calendar math.order prettyprint ;"
|
||||
"10 months 2 months time- 8 months <=> ."
|
||||
"+eq+"
|
||||
}
|
||||
{ $example "USING: accessors calendar math.order prettyprint ;"
|
||||
"2010 1 1 <date> 3 days time- day>> ."
|
||||
"29"
|
||||
}
|
||||
} ;
|
||||
|
||||
{ time+ time- } related-words
|
||||
|
||||
HELP: convert-timezone
|
||||
{ $values { "timestamp" timestamp } { "duration" duration } { "timestamp" timestamp } }
|
||||
{ $description "Converts the " { $snippet "timestamp" } "'s " { $snippet "gmt-offset" } " to the GMT offset represented by the " { $snippet "duration" } "." }
|
||||
{ $examples
|
||||
{ $example "USING: accessors calendar prettyprint ;"
|
||||
"gmt noon instant -5 >>hour convert-timezone gmt-offset>> hour>> ."
|
||||
"-5"
|
||||
}
|
||||
} ;
|
||||
|
||||
HELP: >local-time
|
||||
{ $values { "timestamp" timestamp } { "timestamp" timestamp } }
|
||||
{ $description "Converts the " { $snippet "timestamp" } " to the timezone of your computer." }
|
||||
{ $examples
|
||||
{ $example "USING: accessors calendar kernel prettyprint ;"
|
||||
"now gmt >local-time [ gmt-offset>> ] bi@ = ."
|
||||
"t"
|
||||
}
|
||||
} ;
|
||||
|
|
|
@ -60,6 +60,8 @@ PRIVATE>
|
|||
: month-abbreviation ( n -- string )
|
||||
check-month 1- month-abbreviations nth ;
|
||||
|
||||
: day-counts { 0 31 28 31 30 31 30 31 31 30 31 30 31 } ; inline
|
||||
|
||||
: day-names ( -- array )
|
||||
{
|
||||
"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"
|
||||
|
@ -116,7 +118,7 @@ PRIVATE>
|
|||
: >time< ( timestamp -- hour minute second )
|
||||
[ hour>> ] [ minute>> ] [ second>> ] tri ;
|
||||
|
||||
MEMO: instant ( -- duration ) 0 0 0 0 0 0 <duration> ;
|
||||
: instant ( -- duration ) 0 0 0 0 0 0 <duration> ;
|
||||
: years ( x -- duration ) instant clone swap >>year ;
|
||||
: months ( x -- duration ) instant clone swap >>month ;
|
||||
: days ( x -- duration ) instant clone swap >>day ;
|
||||
|
@ -258,7 +260,7 @@ M: duration <=> [ dt>years ] compare ;
|
|||
: dt>seconds ( duration -- x ) dt>years seconds-per-year * ;
|
||||
: dt>milliseconds ( duration -- x ) dt>seconds 1000 * ;
|
||||
|
||||
GENERIC: time- ( time1 time2 -- time )
|
||||
GENERIC: time- ( time1 time2 -- time3 )
|
||||
|
||||
: convert-timezone ( timestamp duration -- timestamp )
|
||||
over gmt-offset>> over = [ drop ] [
|
||||
|
@ -323,12 +325,9 @@ MEMO: unix-1970 ( -- timestamp )
|
|||
unix-1970 millis milliseconds time+ ;
|
||||
|
||||
: now ( -- timestamp ) gmt >local-time ;
|
||||
|
||||
: hence ( duration -- timestamp ) now swap time+ ;
|
||||
: ago ( duration -- timestamp ) now swap time- ;
|
||||
|
||||
: day-counts { 0 31 28 31 30 31 30 31 31 30 31 30 31 } ; inline
|
||||
|
||||
: zeller-congruence ( year month day -- n )
|
||||
#! Zeller Congruence
|
||||
#! http://web.textfiles.com/computers/formulas.txt
|
||||
|
|
Loading…
Reference in New Issue