8
Write a function or program that accepts a date (as a string in YYYY-MM-DD format) as input and returns a truthy value if that date is "alphabetical," and a falsey value if it isn't.
An alphabetical date is a date whose month, day and year are in alphabetical order when expressed as a string (and when considered specifically in M - D - Y order). For example, Sept. 26 2018 is an alphabetical date:
September 26th 2018 -> September twenty-sixth two thousand eighteen
September
Twenty-sixth
Two thousand eighteen
Another way to think of this challenge: "are the elements of a given date lexically sorted?"
Notes:
- 2018 is represented as "two thousand eighteen," not "twenty eighteen" or "two zero one eight." For another example, the year 1456 would be represented as "one thousand four hundred fifty-six," not "fourteen fifty-six."
- 26th is represented as "twenty-sixth," not "twenty-six."
- Each element of the date is considered as a whole. This is why 2018 doesn't automatically fail even though the "e" in eighteen comes before the "t" in two.
The following dates are not alphabetical:
- September 2nd 2018 ("second" should sort ahead of "September")
- April 30th 4000 ("four thousand" should sort ahead of "thirtieth")
Additional Rules:
- You will receive the date as a string, formatted like
YYYY-MM-DD. The year will always have four digits, and the month and day will always have two digits each. Zero-padding is not represented in the string conversion (e.g., '2000-01-01' is 'January first two thousand' as you'd expect). - You may assume that dates will always be valid (no February 30th, no Smarch 1st) and that the value of the year will be positive (no dates B.C.), but the date may be far in the future ("in the year
twonine thousand..."). - You should return a truthy or falsey value, not necessarily a boolean
TrueorFalse. If you do this in Javascript and want to return'0'and0that's fine. Of course, if you want to return a boolean, feel free. - Standard loopholes are forbidden.
- This is
code-golf
More Examples of Alphabetical Dates
- 2066-01-02 (January second, two thousand sixty-six)
- 1000-04-08 (April eighth, one thousand)
- 6000-08-01 (August first, six thousand)
More Examples of Non-Alphabetical Dates
- 1066-01-02 (January second, one thousand sixty-six)
- 1000-04-07 (April seventh, one thousand)
- 8000-08-01 (August first, eight thousand)
2Lousy Smarch weather. – AdmBorkBork – 2018-09-26T19:05:13.940
@Arnauld Um, no? Looks like 2018-09-02 is falsy, while 2018-09-26 is truthy (when given as in the question). – Erik the Outgolfer – 2018-09-26T19:12:09.083
@EriktheOutgolfer Right. I totally misread the challenge. (Maybe it should be rephrased as Is the date lexically sorted? or something like that.) – Arnauld – 2018-09-26T19:15:23.880
@Arnauld I tweaked the first paragraph and included a line with your suggested wording a bit further in, hopefully to the delight of future readers. Thank you! – souldeux – 2018-09-26T19:22:26.407
All the years in your examples and test cases are now in the form
N0##resultingN thousand ##. Would a year where the second digit isn't a zero also start withN thousand, or would it be more how people would actually say year in general (i.e. will1991beone thousand nine hundred and ninety-oneornineteen hundred ninety-one). – Kevin Cruijssen – 2018-09-27T07:17:50.013IMO, this post should contain the details of how to convert the number of year to its name. And it currently unclear, at least to me. – tsh – 2018-09-27T07:56:56.160
1The year is always the spelled-out number. 1444 is one thousand four hundred forty-four. 1991 is one thousand nine hundred ninety-one. – souldeux – 2018-09-27T12:06:04.523