Python 3, 66 63 bytes
Thanks to ideas from JavaScript / ES answers here I managed to squeeze some bytes. Index a dictionary - non-existent keys will raise a KeyError
. The following code works in local time zone
import time;print({1:'Merry Christmas'}['c 25'in time.ctime()])
The output format for ctime
isn't locale-dependent - the format is always ~ 'Sun Dec 25 19:23:05 2016'
. Since only in December does the 3-letter abbreviation end with c
, it is safe to use 'c 25'in time.ctime()
here.
Previous version:
This works in UTC time zone. For local time zone one needs to s/gm/local
for 3 more bytes. For Python 2, one can remove parentheses from print
for 65 bytes.
import time;print({(12,25):'Merry Christmas'}[time.gmtime()[1:3]])
The construct throws KeyError
on other dates:
>>> import time;print({(1,1):'Happy New Year'}[time.gmtime()[1:3]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: (12, 25)