Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Short Date into English Long Date

Convert short date format into English long date in as few bytes as possible.

Input

Input will be in the form of a string with format, yyyy-mm-dd, with zero padding optional for all values. You can assume that this is syntactically correct, but not necessarily a valid date. Negative year values do not need to be supported.

Output

You must convert the date into the English long date format (e.g. 14th February 2017). Zero padding here is not allowed.

If the date is invalid (e.g. 2011-02-29), then this must be recognised in some way. Throwing an exception is allowed.

More examples can be seen below.

Test Cases

"1980年05月12日" -> 12th May 1980
"2005年12月3日" -> 3rd December 2005
"150-4-21" -> 21st April 150
"2011-2-29" -> (error/invalid)
"1999-10-35" -> (error/invalid)

Answer*

Draft saved
Draft discarded
Cancel
8
  • \$\begingroup\$ You can save a byte by removing the space between int(x) and for in your list comp. \$\endgroup\$ Commented Jun 29, 2017 at 0:03
  • \$\begingroup\$ @ChristianDean Thanks, done! \$\endgroup\$ Commented Jun 29, 2017 at 0:05
  • \$\begingroup\$ (('st','nd','rd')[b%10-1]if b<4 or 20<b<24 else'th') instead of your current conditional for -3 bytes. \$\endgroup\$ Commented Jun 29, 2017 at 2:19
  • \$\begingroup\$ @ValueInk Sadly, that will produce 31th. Another way I thought of breaking it down was 'th' if not 0<b%10<4 or 10<b<14 but it didn't save any bytes. \$\endgroup\$ Commented Jun 29, 2017 at 4:08
  • \$\begingroup\$ In that case, abuse type coersion. (3<b<21)+(23<b<31) for -1 byte. Try it online! \$\endgroup\$ Commented Jun 29, 2017 at 4:19

AltStyle によって変換されたページ (->オリジナル) /