diff --git a/basis/calendar/calendar-docs.factor b/basis/calendar/calendar-docs.factor index b2e42958ef..143fe3ac30 100644 --- a/basis/calendar/calendar-docs.factor +++ b/basis/calendar/calendar-docs.factor @@ -26,54 +26,6 @@ HELP: } } ; -HELP: month-names -{ $values { "value" object } } -{ $description "Returns an array with the English names of all the months." } -{ $warning "Do not use this array for looking up a month name directly. Use " { $link month-name } " instead." } ; - -HELP: month-name -{ $values { "obj" { $or integer timestamp } } { "string" string } } -{ $description "Looks up the month name and returns it as a string. January has an index of 1 instead of zero." } ; - -HELP: month-abbreviations -{ $values { "value" array } } -{ $description "Returns an array with the English abbreviated names of all the months." } -{ $warning "Do not use this array for looking up a month name directly. Use " { $link month-abbreviation } " instead." } ; - -HELP: month-abbreviation -{ $values { "n" integer } { "string" string } } -{ $description "Looks up the abbreviated month name and returns it as a string. January has an index of 1 instead of zero." } ; - -HELP: day-names -{ $values { "value" array } } -{ $description "Returns an array with the English names of the days of the week." } ; - -HELP: day-name -{ $values { "obj" { $or integer timestamp } } { "string" string } } -{ $description "Looks up the day name and returns it as a string." } ; - -HELP: day-abbreviations2 -{ $values { "value" array } } -{ $description "Returns an array with the abbreviated English names of the days of the week. This abbreviation is two characters long." } ; - -HELP: day-abbreviation2 -{ $values { "n" integer } { "string" string } } -{ $description "Looks up the abbreviated day name and returns it as a string. This abbreviation is two characters long." } ; - -HELP: day-abbreviations3 -{ $values { "value" array } } -{ $description "Returns an array with the abbreviated English names of the days of the week. This abbreviation is three characters long." } ; - -HELP: day-abbreviation3 -{ $values { "n" integer } { "string" string } } -{ $description "Looks up the abbreviated day name and returns it as a string. This abbreviation is three characters long." } ; - -{ - day-name day-names - day-abbreviation2 day-abbreviations2 - day-abbreviation3 day-abbreviations3 -} related-words - HELP: average-month { $values { "value" ratio } } { $description "The length of an average month averaged over 400 years. Used internally for adding an arbitrary real number of months to a timestamp." } ; @@ -617,21 +569,6 @@ ARTICLE: "relative-timestamps" "Relative timestamps" noon } ; -ARTICLE: "days" "Day operations" -"Naming days:" -{ $subsections - day-abbreviation2 - day-abbreviations2 - day-abbreviation3 - day-abbreviations3 - day-name - day-names -} -"Calculating a Julian day number:" -{ $subsections julian-day-number } -"Calculate a timestamp:" -{ $subsections julian-day-number>date } ; - ARTICLE: "calendar-facts" "Calendar facts" "Calendar facts:" { $subsections @@ -644,7 +581,11 @@ ARTICLE: "calendar-facts" "Calendar facts" days-in-month day-of-year day-of-week -} ; +} +"Calculating a Julian day number:" +{ $subsections julian-day-number } +"Calculate a timestamp:" +{ $subsections julian-day-number>date } ; ARTICLE: "years" "Year operations" "Leap year predicate:" @@ -652,13 +593,4 @@ ARTICLE: "years" "Year operations" "Find the number of days in a year:" { $subsections days-in-year } ; -ARTICLE: "months" "Month operations" -"Naming months:" -{ $subsections - month-name - month-names - month-abbreviation - month-abbreviations -} ; - ABOUT: "calendar" diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index d8586fe6b7..515a87598f 100644 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -50,71 +50,8 @@ M: timestamp clone (clone) [ clone ] change-gmt-offset ; : ( year -- timestamp ) 1 1 ; inline -ERROR: not-a-month ; -M: not-a-month summary - drop "Months are indexed starting at 1" ; - - - -CONSTANT: month-names - { - "January" "February" "March" "April" "May" "June" - "July" "August" "September" "October" "November" "December" - } - -GENERIC: month-name ( obj -- string ) - -M: integer month-name check-month 1 - month-names nth ; -M: timestamp month-name month>> 1 - month-names nth ; - -ERROR: not-a-month-abbreviation string ; - -CONSTANT: month-abbreviations - { - "Jan" "Feb" "Mar" "Apr" "May" "Jun" - "Jul" "Aug" "Sep" "Oct" "Nov" "Dec" - } - -CONSTANT: month-abbreviations-hash - H{ - { "Jan" 1 } { "Feb" 2 } { "Mar" 3 } - { "Apr" 4 } { "May" 5 } { "Jun" 6 } - { "Jul" 7 } { "Aug" 8 } { "Sep" 9 } - { "Oct" 10 } { "Nov" 11 } { "Dec" 12 } - } - -: month-abbreviation ( n -- string ) - check-month 1 - month-abbreviations nth ; - -: month-abbreviation-index ( string -- n ) - month-abbreviations-hash ?at - [ not-a-month-abbreviation ] unless ; - CONSTANT: day-counts { 0 31 28 31 30 31 30 31 31 30 31 30 31 } -CONSTANT: day-names - { "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" } - -CONSTANT: day-abbreviations2 - { "Su" "Mo" "Tu" "We" "Th" "Fr" "Sa" } - -: day-abbreviation2 ( n -- string ) - day-abbreviations2 nth ; inline - -CONSTANT: day-abbreviations3 - { "Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" } - -CONSTANT: day-abbreviations3-hash - H{ - { "Sun" 0 } { "Mon" 1 } { "Tue" 2 } { "Wed" 3 } - { "Thu" 4 } { "Fri" 5 } { "Sat" 6 } - } - CONSTANT: average-month 30+5/12 CONSTANT: months-per-year 12 CONSTANT: days-per-year 3652425/10000 @@ -443,10 +380,6 @@ M: timestamp days-in-year ( timestamp -- n ) year>> days-in-year ; : day-of-week ( timestamp -- n ) >date< zeller-congruence ; -GENERIC: day-name ( obj -- string ) -M: integer day-name day-names nth ; -M: timestamp day-name day-of-week day-names nth ; - :: (day-of-year) ( year month day -- n ) day-counts month head-slice sum day + year leap-year? [ @@ -568,23 +501,6 @@ M: timestamp december clone 12 >>month ; : last-friday-of-month ( timestamp -- new-timestamp ) 5 last-day-this-month ; : last-saturday-of-month ( timestamp -- new-timestamp ) 6 last-day-this-month ; -CONSTANT: day-predicates - { sunday? monday? tuesday? wednesday? thursday? friday? saturday? } - -: day-predicate ( string -- predicate ) - day-predicates nth ; - -: day-abbreviation3 ( n -- string ) - day-abbreviations3 nth ; inline - -ERROR: not-a-day-abbreviation string ; - -: day-abbreviation3-index ( string -- n ) - day-abbreviations3-hash ?at [ not-a-day-abbreviation ] unless ; inline - -: day-abbreviation3-predicate ( string -- predicate ) - day-abbreviation3-index day-predicates nth ; - : beginning-of-week ( timestamp -- new-timestamp ) midnight sunday ; diff --git a/basis/calendar/english/english-docs.factor b/basis/calendar/english/english-docs.factor new file mode 100644 index 0000000000..3ce629c7fa --- /dev/null +++ b/basis/calendar/english/english-docs.factor @@ -0,0 +1,72 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license.xo +USING: arrays calendar help.markup help.syntax kernel math strings ; +IN: calendar.english + +HELP: month-names +{ $values { "value" object } } +{ $description "Returns an array with the English names of all the months." } +{ $warning "Do not use this array for looking up a month name directly. Use " { $link month-name } " instead." } ; + +HELP: month-name +{ $values { "obj" { $or integer timestamp } } { "string" string } } +{ $description "Looks up the month name and returns it as a string. January has an index of 1 instead of zero." } ; + +HELP: month-abbreviations +{ $values { "value" array } } +{ $description "Returns an array with the English abbreviated names of all the months." } +{ $warning "Do not use this array for looking up a month name directly. Use " { $link month-abbreviation } " instead." } ; + +HELP: month-abbreviation +{ $values { "n" integer } { "string" string } } +{ $description "Looks up the abbreviated month name and returns it as a string. January has an index of 1 instead of zero." } ; + +HELP: day-names +{ $values { "value" array } } +{ $description "Returns an array with the English names of the days of the week." } ; + +HELP: day-name +{ $values { "obj" { $or integer timestamp } } { "string" string } } +{ $description "Looks up the day name and returns it as a string." } ; + +HELP: day-abbreviations2 +{ $values { "value" array } } +{ $description "Returns an array with the abbreviated English names of the days of the week. This abbreviation is two characters long." } ; + +HELP: day-abbreviation2 +{ $values { "n" integer } { "string" string } } +{ $description "Looks up the abbreviated day name and returns it as a string. This abbreviation is two characters long." } ; + +HELP: day-abbreviations3 +{ $values { "value" array } } +{ $description "Returns an array with the abbreviated English names of the days of the week. This abbreviation is three characters long." } ; + +HELP: day-abbreviation3 +{ $values { "n" integer } { "string" string } } +{ $description "Looks up the abbreviated day name and returns it as a string. This abbreviation is three characters long." } ; + +{ + day-name day-names + day-abbreviation2 day-abbreviations2 + day-abbreviation3 day-abbreviations3 +} related-words + +ARTICLE: "months" "Month names in English" +"Naming months:" +{ $subsections + month-name + month-names + month-abbreviation + month-abbreviations +} ; + +ARTICLE: "days" "Day names in English" +"Naming days:" +{ $subsections + day-abbreviation2 + day-abbreviations2 + day-abbreviation3 + day-abbreviations3 + day-name + day-names +} ; diff --git a/basis/calendar/english/english.factor b/basis/calendar/english/english.factor new file mode 100644 index 0000000000..86fc52444f --- /dev/null +++ b/basis/calendar/english/english.factor @@ -0,0 +1,84 @@ +! Copyright (C) 2007 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors assocs calendar kernel math sequences summary ; +IN: calendar.english + +CONSTANT: month-names + { + "January" "February" "March" "April" "May" "June" + "July" "August" "September" "October" "November" "December" + } + +ERROR: not-a-month ; +M: not-a-month summary + drop "Months are indexed starting at 1" ; + +: check-month ( n -- n ) + [ not-a-month ] when-zero ; + +GENERIC: month-name ( obj -- string ) + +M: integer month-name check-month 1 - month-names nth ; +M: timestamp month-name month>> 1 - month-names nth ; + +ERROR: not-a-month-abbreviation string ; + +CONSTANT: month-abbreviations + { + "Jan" "Feb" "Mar" "Apr" "May" "Jun" + "Jul" "Aug" "Sep" "Oct" "Nov" "Dec" + } + +CONSTANT: month-abbreviations-hash + H{ + { "Jan" 1 } { "Feb" 2 } { "Mar" 3 } + { "Apr" 4 } { "May" 5 } { "Jun" 6 } + { "Jul" 7 } { "Aug" 8 } { "Sep" 9 } + { "Oct" 10 } { "Nov" 11 } { "Dec" 12 } + } + +: month-abbreviation ( n -- string ) + check-month 1 - month-abbreviations nth ; + +: month-abbreviation-index ( string -- n ) + month-abbreviations-hash ?at + [ not-a-month-abbreviation ] unless ; + +CONSTANT: day-names + { "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" } + +CONSTANT: day-abbreviations2 + { "Su" "Mo" "Tu" "We" "Th" "Fr" "Sa" } + +: day-abbreviation2 ( n -- string ) + day-abbreviations2 nth ; inline + +CONSTANT: day-abbreviations3 + { "Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" } + +CONSTANT: day-abbreviations3-hash + H{ + { "Sun" 0 } { "Mon" 1 } { "Tue" 2 } { "Wed" 3 } + { "Thu" 4 } { "Fri" 5 } { "Sat" 6 } + } + +CONSTANT: day-predicates + { sunday? monday? tuesday? wednesday? thursday? friday? saturday? } + +: day-predicate ( string -- predicate ) + day-predicates nth ; + +: day-abbreviation3 ( n -- string ) + day-abbreviations3 nth ; inline + +ERROR: not-a-day-abbreviation string ; + +: day-abbreviation3-index ( string -- n ) + day-abbreviations3-hash ?at [ not-a-day-abbreviation ] unless ; inline + +: day-abbreviation3-predicate ( string -- predicate ) + day-abbreviation3-index day-predicates nth ; + +GENERIC: day-name ( obj -- string ) +M: integer day-name day-names nth ; +M: timestamp day-name day-of-week day-names nth ; diff --git a/basis/calendar/english/summary.txt b/basis/calendar/english/summary.txt new file mode 100644 index 0000000000..42968ae5b9 --- /dev/null +++ b/basis/calendar/english/summary.txt @@ -0,0 +1 @@ +English names for time concepts diff --git a/basis/calendar/format/format.factor b/basis/calendar/format/format.factor index 602341bcb0..2ec8942389 100644 --- a/basis/calendar/format/format.factor +++ b/basis/calendar/format/format.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays assocs calendar calendar.format.macros -combinators io io.streams.string kernel math math.functions -math.order math.parser math.parser.private present sequences -typed ; +USING: accessors arrays assocs calendar calendar.english +calendar.format.macros combinators io io.streams.string kernel math +math.functions math.order math.parser math.parser.private present +sequences typed ; IN: calendar.format : pad-00 ( n -- str ) number>string 2 CHAR: 0 pad-head ; diff --git a/basis/formatting/formatting.factor b/basis/formatting/formatting.factor index 09f67f363b..f98d1a04e3 100644 --- a/basis/formatting/formatting.factor +++ b/basis/formatting/formatting.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: accessors arrays assocs calendar combinators +USING: accessors arrays assocs calendar calendar.english combinators combinators.smart fry generalizations io io.streams.string kernel macros math math.functions math.parser namespaces peg.ebnf present prettyprint quotations sequences diff --git a/basis/tools/files/files.factor b/basis/tools/files/files.factor index 185791883f..574dc7d647 100644 --- a/basis/tools/files/files.factor +++ b/basis/tools/files/files.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2008, 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays calendar combinators fry io io.directories -io.files.info kernel math math.parser prettyprint sequences system -vocabs sorting.slots calendar.format ; +USING: accessors arrays calendar calendar.english combinators fry io +io.directories io.files.info kernel math math.parser prettyprint sequences +system vocabs sorting.slots calendar.format ; IN: tools.files