diff --git a/basis/calendar/calendar-docs.factor b/basis/calendar/calendar-docs.factor index 127dc4c60a..cf60d40bf6 100644 --- a/basis/calendar/calendar-docs.factor +++ b/basis/calendar/calendar-docs.factor @@ -322,3 +322,172 @@ HELP: before "9" } } ; + +HELP: +{ $values { "timestamp" timestamp } } +{ $description "Outputs a zero timestamp that consists of zeros for every slot. Used to see if timestamps are valid." } ; + +HELP: valid-timestamp? +{ $values { "timestamp" timestamp } { "?" "a boolean" } } +{ $description "Tests if a timestamp is valid or not." } ; + +HELP: unix-1970 +{ $values { "timestamp" timestamp } } +{ $description "Outputs the beginning of UNIX time, or midnight, January 1, 1970." } ; + +HELP: millis>timestamp +{ $values { "x" number } { "timestamp" timestamp } } +{ $description "Converts a number of milliseconds into a timestamp value in GMT time." } +{ $examples + { $example "USING: accessors calendar prettyprint ;" + "1000 millis>timestamp year>> ." + "1970" + } +} ; + +HELP: gmt +{ $values { "timestamp" timestamp } } +{ $description "Outputs the time right now, but in the GMT timezone." } ; + +{ gmt now } related-words + +HELP: now +{ $values { "timestamp" timestamp } } +{ $description "Outputs the time right now in your computer's timezone." } +{ $examples + { $unchecked-example "USING: calendar prettyprint ;" + "now ." + "T{ timestamp f 2008 9 1 16 38 24+801/1000 T{ duration f 0 0 0 -5 0 0 } }" + } +} ; + +HELP: hence +{ $values { "duration" duration } { "timestamp" timestamp } } +{ $description "Computes a time in the future that is the " { $snippet "duration" } " added to the result of " { $link now } "." } +{ $examples + { $unchecked-example + "USING: calendar prettyprint ;" + "10 hours hence ." + "T{ timestamp f 2008 9 2 2 47 45+943/1000 T{ duration f 0 0 0 -5 0 0 } }" + } +} ; + +HELP: ago +{ $values { "duration" duration } { "timestamp" timestamp } } +{ $description "Computes a time in the past that is the " { $snippet "duration" } " subtracted from the result of " { $link now } "." } +{ $examples + { $unchecked-example + "USING: calendar prettyprint ;" + "3 weeks ago ." + "T{ timestamp f 2008 8 11 16 49 52+99/500 T{ duration f 0 0 0 -5 0 0 } }" + } +} ; + +HELP: zeller-congruence +{ $values { "year" integer } { "month" integer } { "day" integer } { "n" integer } } +{ $description "An implementation of an algorithm that computes the day of the week given a date. Days are indexed starting from Sunday, which is index 0." } +{ $notes "User code should use the " { $link day-of-week } " word, which takes a " { $snippet "timestamp" } " instead of integers." } ; + +HELP: days-in-year +{ $values { "obj" "a timestamp or an integer" } { "n" integer } } +{ $description "Calculates the number of days in a given year." } +{ $examples + { $example "USING: calendar prettyprint ;" + "2004 days-in-year ." + "366" + } +} ; + +HELP: days-in-month +{ $values { "timestamp" timestamp } { "n" integer } } +{ $description "Calculates the number of days in a given month." } +{ $examples + { $example "USING: calendar prettyprint ;" + "2008 8 24 days-in-month ." + "31" + } +} ; + +HELP: day-of-week +{ $values { "timestamp" timestamp } { "n" integer } } +{ $description "Calculates the index of the day of the week. Sunday will result in an index of 0." } +{ $examples + { $example "USING: calendar prettyprint ;" + "now sunday day-of-week ." + "0" + } +} ; + +HELP: day-of-year +{ $values { "timestamp" timestamp } { "n" integer } } +{ $description "Calculates the day of the year, resulting in a number from 1 to 366 (leap years)." } +{ $examples + { $example "USING: calendar prettyprint ;" + "2008 1 4 day-of-year ." + "4" + } +} ; + +HELP: day-this-week +{ $values { "timestamp" timestamp } { "n" integer } { "timestamp" timestamp } } +{ $description "Implementation word to calculate the day of the week relative to the timestamp. Sunday is the first day of the week, so the resulting " { $snippet "timestamp" } " will be Sunday or after, and before Saturday." } +{ $examples + { $example "USING: calendar kernel prettyprint ;" + "now 0 day-this-week now sunday = ." + "t" + } +} ; + +HELP: sunday +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns the Sunday from the current week, which starts on a Sunday." } ; + +HELP: monday +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns the Monday from the current week, which starts on a Sunday." } ; + +HELP: tuesday +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns the Tuesday from the current week, which starts on a Sunday." } ; + +HELP: wednesday +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns the Wednesday from the current week, which starts on a Sunday." } ; + +HELP: thursday +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns the Thursday from the current week, which starts on a Sunday." } ; + +HELP: friday +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns the Friday from the current week, which starts on a Sunday." } ; + +HELP: saturday +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns the Saturday from the current week, which starts on a Sunday." } ; + +{ sunday monday tuesday wednesday thursday friday saturday } related-words + +HELP: midnight +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns a timestamp that represents today at midnight, or the beginning of the day." } ; + +HELP: noon +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Returns a timestamp that represents today at noon, or the middle of the day." } ; + +HELP: beginning-of-month +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Outputs a timestamp with the day set to one." } ; + +HELP: beginning-of-week +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Outputs a timestamp where the day of the week is Sunday." } ; + +HELP: beginning-of-year +{ $values { "timestamp" timestamp } { "new-timestamp" timestamp } } +{ $description "Outputs a timestamp with the month and day set to one, or January 1 of the input timestamp." } ; + +HELP: time-since-midnight +{ $values { "timestamp" timestamp } { "duration" duration } } +{ $description "Calculates a " { $snippet "duration" } " that represents the elapsed time since midnight of the input " { $snippet "timestamp" } "." } ; diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index 5710949af5..096546349d 100755 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -316,7 +316,7 @@ M: duration time- : unix-1970 ( -- timestamp ) 1970 1 1 0 0 0 instant ; -: millis>timestamp ( n -- timestamp ) +: millis>timestamp ( x -- timestamp ) >r unix-1970 r> milliseconds time+ ; : timestamp>millis ( timestamp -- n ) @@ -370,13 +370,13 @@ M: timestamp days-in-year ( timestamp -- n ) year>> days-in-year ; : day-this-week ( timestamp n -- timestamp ) day-offset days time+ ; -: sunday ( timestamp -- timestamp ) 0 day-this-week ; -: monday ( timestamp -- timestamp ) 1 day-this-week ; -: tuesday ( timestamp -- timestamp ) 2 day-this-week ; -: wednesday ( timestamp -- timestamp ) 3 day-this-week ; -: thursday ( timestamp -- timestamp ) 4 day-this-week ; -: friday ( timestamp -- timestamp ) 5 day-this-week ; -: saturday ( timestamp -- timestamp ) 6 day-this-week ; +: sunday ( timestamp -- new-timestamp ) 0 day-this-week ; +: monday ( timestamp -- new-timestamp ) 1 day-this-week ; +: tuesday ( timestamp -- new-timestamp ) 2 day-this-week ; +: wednesday ( timestamp -- new-timestamp ) 3 day-this-week ; +: thursday ( timestamp -- new-timestamp ) 4 day-this-week ; +: friday ( timestamp -- new-timestamp ) 5 day-this-week ; +: saturday ( timestamp -- new-timestamp ) 6 day-this-week ; : midnight ( timestamp -- new-timestamp ) clone 0 >>hour 0 >>minute 0 >>second ; inline diff --git a/basis/io/buffers/buffers-tests.factor b/basis/io/buffers/buffers-tests.factor index 74a1797efc..b3c5c4ee90 100755 --- a/basis/io/buffers/buffers-tests.factor +++ b/basis/io/buffers/buffers-tests.factor @@ -4,7 +4,7 @@ sequences tools.test namespaces byte-arrays strings accessors destructors ; : buffer-set ( string buffer -- ) - over >byte-array over buffer-ptr byte-array>memory + over >byte-array over ptr>> byte-array>memory >r length r> buffer-reset ; : string>buffer ( string -- buffer ) diff --git a/extra/cpu/8080/8080-docs.factor b/unmaintained/cpu/8080/8080-docs.factor similarity index 100% rename from extra/cpu/8080/8080-docs.factor rename to unmaintained/cpu/8080/8080-docs.factor diff --git a/extra/cpu/8080/8080.factor b/unmaintained/cpu/8080/8080.factor similarity index 100% rename from extra/cpu/8080/8080.factor rename to unmaintained/cpu/8080/8080.factor diff --git a/extra/cpu/8080/authors.txt b/unmaintained/cpu/8080/authors.txt similarity index 100% rename from extra/cpu/8080/authors.txt rename to unmaintained/cpu/8080/authors.txt diff --git a/extra/cpu/8080/emulator/authors.txt b/unmaintained/cpu/8080/emulator/authors.txt similarity index 100% rename from extra/cpu/8080/emulator/authors.txt rename to unmaintained/cpu/8080/emulator/authors.txt diff --git a/extra/cpu/8080/emulator/emulator-docs.factor b/unmaintained/cpu/8080/emulator/emulator-docs.factor similarity index 100% rename from extra/cpu/8080/emulator/emulator-docs.factor rename to unmaintained/cpu/8080/emulator/emulator-docs.factor diff --git a/extra/cpu/8080/emulator/emulator.factor b/unmaintained/cpu/8080/emulator/emulator.factor similarity index 100% rename from extra/cpu/8080/emulator/emulator.factor rename to unmaintained/cpu/8080/emulator/emulator.factor diff --git a/extra/cpu/8080/emulator/summary.txt b/unmaintained/cpu/8080/emulator/summary.txt similarity index 100% rename from extra/cpu/8080/emulator/summary.txt rename to unmaintained/cpu/8080/emulator/summary.txt diff --git a/extra/cpu/8080/emulator/tags.txt b/unmaintained/cpu/8080/emulator/tags.txt similarity index 100% rename from extra/cpu/8080/emulator/tags.txt rename to unmaintained/cpu/8080/emulator/tags.txt diff --git a/extra/cpu/8080/summary.txt b/unmaintained/cpu/8080/summary.txt similarity index 100% rename from extra/cpu/8080/summary.txt rename to unmaintained/cpu/8080/summary.txt diff --git a/extra/cpu/8080/tags.txt b/unmaintained/cpu/8080/tags.txt similarity index 100% rename from extra/cpu/8080/tags.txt rename to unmaintained/cpu/8080/tags.txt diff --git a/extra/cpu/8080/test/test.factor b/unmaintained/cpu/8080/test/test.factor similarity index 100% rename from extra/cpu/8080/test/test.factor rename to unmaintained/cpu/8080/test/test.factor