calendar.english: new vocab for english names for days and months

This moves all the english-centric words from the calendar vocab which
was getting kind of big to calendar.english. It should make it easier to
see which vocabs make language assumptions.
char-rename
Björn Lindqvist 2017-01-03 15:48:08 +01:00
parent b9030b953e
commit f9b9ce20f2
10 changed files with 176 additions and 171 deletions

View File

@ -26,54 +26,6 @@ HELP: <date>
} }
} ; } ;
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 HELP: average-month
{ $values { "value" ratio } } { $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." } ; { $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 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" ARTICLE: "calendar-facts" "Calendar facts"
"Calendar facts:" "Calendar facts:"
{ $subsections { $subsections
@ -644,7 +581,11 @@ ARTICLE: "calendar-facts" "Calendar facts"
days-in-month days-in-month
day-of-year day-of-year
day-of-week day-of-week
} ; }
"Calculating a Julian day number:"
{ $subsections julian-day-number }
"Calculate a timestamp:"
{ $subsections julian-day-number>date } ;
ARTICLE: "years" "Year operations" ARTICLE: "years" "Year operations"
"Leap year predicate:" "Leap year predicate:"
@ -652,13 +593,4 @@ ARTICLE: "years" "Year operations"
"Find the number of days in a year:" "Find the number of days in a year:"
{ $subsections days-in-year } ; { $subsections days-in-year } ;
ARTICLE: "months" "Month operations"
"Naming months:"
{ $subsections
month-name
month-names
month-abbreviation
month-abbreviations
} ;
ABOUT: "calendar" ABOUT: "calendar"

View File

@ -50,71 +50,8 @@ M: timestamp clone (clone) [ clone ] change-gmt-offset ;
: <year-gmt> ( year -- timestamp ) : <year-gmt> ( year -- timestamp )
1 1 <date-gmt> ; inline 1 1 <date-gmt> ; inline
ERROR: not-a-month ;
M: not-a-month summary
drop "Months are indexed starting at 1" ;
<PRIVATE
: check-month ( n -- n )
[ not-a-month ] when-zero ;
PRIVATE>
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-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: average-month 30+5/12
CONSTANT: months-per-year 12 CONSTANT: months-per-year 12
CONSTANT: days-per-year 3652425/10000 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 ) : day-of-week ( timestamp -- n )
>date< zeller-congruence ; >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-of-year) ( year month day -- n )
day-counts month head-slice sum day + day-counts month head-slice sum day +
year leap-year? [ 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-friday-of-month ( timestamp -- new-timestamp ) 5 last-day-this-month ;
: last-saturday-of-month ( timestamp -- new-timestamp ) 6 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 ) : beginning-of-week ( timestamp -- new-timestamp )
midnight sunday ; midnight sunday ;

View File

@ -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
} ;

View File

@ -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 ;

View File

@ -0,0 +1 @@
English names for time concepts

View File

@ -1,9 +1,9 @@
! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman. ! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs calendar calendar.format.macros USING: accessors arrays assocs calendar calendar.english
combinators io io.streams.string kernel math math.functions calendar.format.macros combinators io io.streams.string kernel math
math.order math.parser math.parser.private present sequences math.functions math.order math.parser math.parser.private present
typed ; sequences typed ;
IN: calendar.format IN: calendar.format
: pad-00 ( n -- str ) number>string 2 CHAR: 0 pad-head ; : pad-00 ( n -- str ) number>string 2 CHAR: 0 pad-head ;

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 John Benediktsson ! Copyright (C) 2008 John Benediktsson
! See http://factorcode.org/license.txt for BSD license ! 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 combinators.smart fry generalizations io io.streams.string
kernel macros math math.functions math.parser namespaces kernel macros math math.functions math.parser namespaces
peg.ebnf present prettyprint quotations sequences peg.ebnf present prettyprint quotations sequences

View File

@ -1,8 +1,8 @@
! Copyright (C) 2008, 2009 Doug Coleman. ! Copyright (C) 2008, 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays calendar combinators fry io io.directories USING: accessors arrays calendar calendar.english combinators fry io
io.files.info kernel math math.parser prettyprint sequences system io.directories io.files.info kernel math math.parser prettyprint sequences
vocabs sorting.slots calendar.format ; system vocabs sorting.slots calendar.format ;
IN: tools.files IN: tools.files
<PRIVATE <PRIVATE

View File

@ -1,8 +1,8 @@
USING: accessors arrays assocs calendar calendar.format calendar.format.macros USING: accessors arrays assocs calendar calendar.english calendar.format
formatting fry grouping io io.crlf io.encodings.ascii io.encodings.binary calendar.format.macros formatting fry grouping io io.crlf io.encodings.ascii
io.encodings.string io.encodings.utf7 io.encodings.utf8 io.sockets io.encodings.binary io.encodings.string io.encodings.utf7 io.encodings.utf8
io.sockets.secure io.streams.duplex io.streams.string kernel math math.parser io.sockets io.sockets.secure io.streams.duplex io.streams.string kernel math
sequences splitting strings ; math.parser sequences splitting strings ;
QUALIFIED: pcre QUALIFIED: pcre
IN: imap IN: imap

View File

@ -1,6 +1,6 @@
! Copyright (C) 2009 Doug Coleman. ! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs calendar combinators USING: accessors arrays assocs calendar.english combinators
combinators.smart io.encodings.utf8 io.files kernel math.parser combinators.smart io.encodings.utf8 io.files kernel math.parser
memoize namespaces sequences splitting unicode ; memoize namespaces sequences splitting unicode ;
IN: zoneinfo IN: zoneinfo