Merge branch 'master' of git://factorcode.org/git/factor
commit
e27d6b31d2
|
@ -184,7 +184,7 @@ HELP: time+
|
||||||
{ $description "Adds two durations to produce a duration or adds a timestamp and a duration to produce a timestamp. The calculation takes timezones into account." }
|
{ $description "Adds two durations to produce a duration or adds a timestamp and a duration to produce a timestamp. The calculation takes timezones into account." }
|
||||||
{ $examples
|
{ $examples
|
||||||
{ $example "USING: calendar math.order prettyprint ;"
|
{ $example "USING: calendar math.order prettyprint ;"
|
||||||
"10 months 2 months time+ 1 year <=> ."
|
"10 months 2 months time+ 1 years <=> ."
|
||||||
"+eq+"
|
"+eq+"
|
||||||
}
|
}
|
||||||
{ $example "USING: accessors calendar math.order prettyprint ;"
|
{ $example "USING: accessors calendar math.order prettyprint ;"
|
||||||
|
@ -193,3 +193,109 @@ HELP: time+
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
HELP: dt>years
|
||||||
|
{ $values { "duration" duration } { "x" number } }
|
||||||
|
{ $description "Calculates the length of a duration in years." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: calendar prettyprint ;"
|
||||||
|
"6 months dt>years ."
|
||||||
|
"1/2"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: dt>months
|
||||||
|
{ $values { "duration" duration } { "x" number } }
|
||||||
|
{ $description "Calculates the length of a duration in months." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: calendar prettyprint ;"
|
||||||
|
"30 days dt>months ."
|
||||||
|
"16000/16233"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: dt>days
|
||||||
|
{ $values { "duration" duration } { "x" number } }
|
||||||
|
{ $description "Calculates the length of a duration in days." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: calendar prettyprint ;"
|
||||||
|
"6 hours dt>days ."
|
||||||
|
"1/4"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: dt>hours
|
||||||
|
{ $values { "duration" duration } { "x" number } }
|
||||||
|
{ $description "Calculates the length of a duration in hours." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: calendar prettyprint ;"
|
||||||
|
"3/4 days dt>hours ."
|
||||||
|
"18"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
HELP: dt>minutes
|
||||||
|
{ $values { "duration" duration } { "x" number } }
|
||||||
|
{ $description "Calculates the length of a duration in minutes." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: calendar prettyprint ;"
|
||||||
|
"6 hours dt>minutes ."
|
||||||
|
"360"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
HELP: dt>seconds
|
||||||
|
{ $values { "duration" duration } { "x" number } }
|
||||||
|
{ $description "Calculates the length of a duration in seconds." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: calendar prettyprint ;"
|
||||||
|
"6 minutes dt>seconds ."
|
||||||
|
"360"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: dt>milliseconds
|
||||||
|
{ $values { "duration" duration } { "x" number } }
|
||||||
|
{ $description "Calculates the length of a duration in milliseconds." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: calendar prettyprint ;"
|
||||||
|
"6 seconds 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 )
|
: month-abbreviation ( n -- string )
|
||||||
check-month 1- month-abbreviations nth ;
|
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 )
|
: day-names ( -- array )
|
||||||
{
|
{
|
||||||
"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"
|
"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"
|
||||||
|
@ -116,7 +118,7 @@ PRIVATE>
|
||||||
: >time< ( timestamp -- hour minute second )
|
: >time< ( timestamp -- hour minute second )
|
||||||
[ hour>> ] [ minute>> ] [ second>> ] tri ;
|
[ 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 ;
|
: years ( x -- duration ) instant clone swap >>year ;
|
||||||
: months ( x -- duration ) instant clone swap >>month ;
|
: months ( x -- duration ) instant clone swap >>month ;
|
||||||
: days ( x -- duration ) instant clone swap >>day ;
|
: 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>seconds ( duration -- x ) dt>years seconds-per-year * ;
|
||||||
: dt>milliseconds ( duration -- x ) dt>seconds 1000 * ;
|
: dt>milliseconds ( duration -- x ) dt>seconds 1000 * ;
|
||||||
|
|
||||||
GENERIC: time- ( time1 time2 -- time )
|
GENERIC: time- ( time1 time2 -- time3 )
|
||||||
|
|
||||||
: convert-timezone ( timestamp duration -- timestamp )
|
: convert-timezone ( timestamp duration -- timestamp )
|
||||||
over gmt-offset>> over = [ drop ] [
|
over gmt-offset>> over = [ drop ] [
|
||||||
|
@ -323,12 +325,9 @@ MEMO: unix-1970 ( -- timestamp )
|
||||||
unix-1970 millis milliseconds time+ ;
|
unix-1970 millis milliseconds time+ ;
|
||||||
|
|
||||||
: now ( -- timestamp ) gmt >local-time ;
|
: now ( -- timestamp ) gmt >local-time ;
|
||||||
|
|
||||||
: hence ( duration -- timestamp ) now swap time+ ;
|
: hence ( duration -- timestamp ) now swap time+ ;
|
||||||
: ago ( 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 ( year month day -- n )
|
||||||
#! Zeller Congruence
|
#! Zeller Congruence
|
||||||
#! http://web.textfiles.com/computers/formulas.txt
|
#! http://web.textfiles.com/computers/formulas.txt
|
||||||
|
@ -395,7 +394,6 @@ M: timestamp days-in-year ( timestamp -- n ) year>> days-in-year ;
|
||||||
: time-since-midnight ( timestamp -- duration )
|
: time-since-midnight ( timestamp -- duration )
|
||||||
dup midnight time- ;
|
dup midnight time- ;
|
||||||
|
|
||||||
|
|
||||||
M: timestamp sleep-until timestamp>millis sleep-until ;
|
M: timestamp sleep-until timestamp>millis sleep-until ;
|
||||||
|
|
||||||
M: duration sleep hence sleep-until ;
|
M: duration sleep hence sleep-until ;
|
||||||
|
|
Loading…
Reference in New Issue