10
\$\begingroup\$

September 1993 is known on Usenet as the September that never ended. Thus, for example, the day this question is being posted is Saturday, September 8740, 1993.

Your program or function should take any Gregorian date (with positive year) as input and return the same date as output if it's prior to September 1993 or the date on the September 1993 calendar if thereafter.

You may accept YYYY-MM-DD, YYYY/MM/DD, MM/DD/YYYY, DD/MM/YYYY, D-Monthnameabbr-YYYY, or any other popular format that uses the entirety of the year (as opposed to the year modulo 100). You need only accept one such format, of your choosing. Output format must match the input format.

Sample input → output:

  • Sunday, 6 August 2017 → Sunday, 8741 September 1993
  • Tuesday, 28 January 1986 → Tuesday, 28 January 1986

Or:

  • 2017-08-06 → 1993-09-8741
  • 1986-01-28 → 1986-01-28

In the interest of more interesting answers, the use of a built-in function designed for this purpose (such as the UN*X sdate command) is disallowed. Aside from that and the standard exceptions, this is golf, so the shortest answer wins.

\$\endgroup\$
  • 1
    \$\begingroup\$ you mean I can't use DateDifference so that people here can comment on Mathematica's builtins??? \$\endgroup\$ – J42161217 Aug 5 '17 at 23:28
  • \$\begingroup\$ @Jenny_mathy, this DateDifference? I guess you can use it, yeah, why not? \$\endgroup\$ – msh210 Aug 6 '17 at 0:51
2
\$\begingroup\$

JavaScript (ES6), 48 bytes

f=
s=>(d=new Date(s)/864e5-8643|0)>9?'1993-09-'+d:s
<input size=10 oninput=o.textContent=/\d{4}(-\d\d){2}/.test(this.value)?f(this.value):``><pre id=o>

Based on @Mr.Xcoder's algorithm.

\$\endgroup\$
3
\$\begingroup\$

Python 3, 109 bytes

from datetime import*
i=input()
z=date(*map(int,i.split())).toordinal()-727806
print([i,'1993 09 %d'%z][z>9])

Try it online!

-59 bytes thanks to notjagan
-3 bytes thanks to Mr. Xcoder
-2 bytes thanks to officialaimm
-12 bytes thanks to Jonathan Allan

\$\endgroup\$
  • \$\begingroup\$ -54 bytes. \$\endgroup\$ – notjagan Aug 6 '17 at 4:49
  • 1
    \$\begingroup\$ Or better yet, -59 bytes. \$\endgroup\$ – notjagan Aug 6 '17 at 5:01
  • 1
    \$\begingroup\$ 123 bytes (-62) \$\endgroup\$ – Mr. Xcoder Aug 6 '17 at 7:27
  • 1
    \$\begingroup\$ -8644+1 can be -8643.. \$\endgroup\$ – officialaimm Aug 6 '17 at 7:45
  • 1
    \$\begingroup\$ @Mr.Xcoder Needs to be z>9 otherwise you lose the leading zero on the day. \$\endgroup\$ – Neil Aug 6 '17 at 10:37
2
\$\begingroup\$

Perl 5, 102 + 16 (-MTime::Local -F-) = 118 bytes

$,='-';say @F=($t=timelocal(0,0,0,$F[2],$F[1]-1,$F[0]-1900)-749433599)>0?(1993,'09',31+int$t/86400):@F

Try it online!

Takes the date as "YYYY-MM-DD"

I think I did the count right on the command line options. I'm sure someone will correct me if I didn't.

\$\endgroup\$
2
\$\begingroup\$

Mathematica, 55 bytes

If[(s=#&@@{1993,9}~DateDifference~#)>0,{1993,9,s+1},#]&

I/O

{2017, 8, 6} ->{1993, 9, 8741}
{1986, 1, 28}->{1986, 1, 28}

-6 bytes thanx to user202729

\$\endgroup\$
  • \$\begingroup\$ Would you consider shift the time mark {1993,9,1} back by a day, so as to remove the +1, saving 2 bytes? \$\endgroup\$ – user202729 Aug 6 '17 at 15:07
  • \$\begingroup\$ Thanks. I should try to be more polite next time. And I don't even know {1993,9,0} is allowed. \$\endgroup\$ – user202729 Aug 6 '17 at 15:22
1
\$\begingroup\$

C# (.NET Core), 107 bytes

s=>{var d=(System.DateTime.Parse(s)-new System.DateTime(1993,8,31)).TotalDays;return d<1?s:"9/"+d+"/1993";}

Try it online!

Takes dates as M/D/YYYY (numbers below 10 written with only 1 digit). Written from my mobile phone using the API by heart.

\$\endgroup\$
1
\$\begingroup\$

Gaia, 78 bytes

ℍZ¤∨4Ė
:'//d¦[1993₉31];>\{\‡:(…1993>↑¦365+¦¤ṇ↑∂K∂k,=;((<¤)-243]_ḥΣ“1993/09/”¤+}?

Try it online!

Explanation

First, we have a helper function that determines if a year is a leap year.

ℍ       100
 Z      Divmod year by 100, pushing the first 2 digits, then the second 2 digits
  ¤     Swap
   ∨    Logical OR, gives the left-most non-zero number
    4Ė  Check for divisibility by 4

The main function does the rest of the work:

:              Push two copies of the input.
'//            Split the top on on slashes.
d¦             Parse each section as a number.
[1993₉31]      Push the list [1993 9 31].
;>             Copy the date and check if its less than that.
\              If it is, delete the list and leave the input string on top.
{              Else:
 :(             Copy the date and get the year.
 …1993>         Get the range from 1993 to year-1.
 ↑¦365+¦        Map each to 365+(whether it's a leap year).
 ¤              Swap, bring the date back to the top.
 ṇ↑             Pull out the year and check if it's a leap year.
 ∂K∂k,          Push the pair of lists [[days in months in a leap year] [days in months]]
 =              Index the result of checking if the year is a leap year into the pair.
 ;((<           Get the first (month number - 1) elements.
 ¤              Swap, bring date back to the top.
 )              Get the day.
 -243           Push -243 (243 is the number of days between Jan 1 1993 and Sept 1 1993).
 ]              Wrap everything in a list.
 _              Flatten the list.
 ḥ              Remove the first element (the input string).
 Σ              Sum it.
 “1993/09/”¤+   Append the resulting number to "1993/09/".
}?             (end if)
               Implicitly display whatever is on top of the stack.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.