Usenet時間での日付は何ですか?


9

1993年9月は、終わらない9月としてUsenetで知られています。したがって、たとえば、この質問が投稿されている日は、1993年9月8740土曜日です。

プログラムまたは関数は、グレゴリオ暦の日付(正の年を含む)を入力として受け取り、1993年9月より前の場合は出力と同じ日付を返し、それ以降の場合は1993年9月のカレンダーの日付を返します。

YYYY-MM-DD、YYYY / MM / DD、MM / DD / YYYY、DD / MM / YYYY、D-Monthnameabbr-YYYY、または年全体を使用する他の一般的な形式(年モジュロ100)。あなたはあなたが選んだそのようなフォーマットを一つだけ受け入れる必要があります。出力形式は入力形式と一致する必要があります。

入力例→出力例:

  • 2017年8月6日日曜日→1993年9月8741日曜日
  • 1986年1月28日火曜日→1986年1月28日火曜日

または:

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

より興味深い答えのために、この目的のために設計された組み込み関数(UN * X sdateコマンドなど)の使用は許可されていません。それと標準の例外を除いて、これはゴルフなので、最も短い答えが勝ちます。


1
ここにいる人々がMathematicaのビルトインにコメントできるように、私はDateDifferenceを使用できないことを意味します???
J42161217 2017

@Jenny_mathy、このDateDifference?使用できると思いますね。
msh210 2017

回答:


2

JavaScript(ES6)、48バイト

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>

@ Mr.Xcoderのアルゴリズムに基づいています。


3

Python 3、109バイト

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

オンラインでお試しください!

-59
バイト(notjaganのおかげ)-3バイト(Xcoder氏の
おかげ)-2バイト(officialaimmの
おかげ)-12バイト(Jonathan Allanのおかげ)



1
またはさらに良いことに、-59バイトです。
notjagan 2017


1
-8644+1することができます-8643..
officialaimm

1
@ Mr.Xcoderでなければz>9、その日の先行ゼロを失うことになります。
Neil

2

Mathematica、55バイト

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バイト、ユーザー202729に感謝


{1993,9,1}を削除して+12バイトを節約するために、タイムマークを1日戻すことを検討しますか?
user202729 2017

ありがとう。次回はもっと丁寧になろうと思います。そして、私{1993,9,0}は許可されていることさえ知りません。
user202729 2017

1

Perl 5、102 + 16(-MTime :: Local -F-)= 118バイト

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

オンラインでお試しください!

日付を "YYYY-MM-DD"とする

私はコマンドラインオプションで正しくカウントしたと思います。私が修正しなかった場合、誰かが私を修正すると確信しています。



1

Gaia、78バイト

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

オンラインでお試しください!

説明

まず、うるう年かどうかを判断するヘルパー関数があります。

ℍ       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

main関数は残りの作業を行います:

:              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.
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.