Pi Day, Pi Minute, or Pi Second?
Javascript (ES6), 114 112 - 15 = 97 bytes
x=>['Pi Day','Pi Minute','Pi Second'].find((x,i)=>[/ar 14/,/(03|15):14:/,/03:14/][i].test(Date()))||'No Pi Time'
Ungolfed:
x=>
['Pi Day', 'Pi Minute', 'Pi Second'] // array of outputs
.find( // find first element in the array
(x, i)=> // which returns truthy for this function
[/ar 14/, /(03|15):14:/, /03:14/] // array of regex patterns
[i] // get corresponding regex based on index
.test(Date()) // test it against current date, date is automatically cast to string
) || 'No Pi Time' // if no result, then return "No Pi Time"
Thanks for -2 bytes @edc65
Ruby, 125 124 chars
i=[*[(t=Time.new).month,t.day,t.hour,t.min,t.sec].each_cons(2)].index [3,14];i&&$><<['Pi Day','','Pi Minute','Pi Second'][i]
Alas, the cleverer %i[month day hour min sec].map{|x|Time.new.send x}
is longer.
The key here is the use of each_cons
to avoid repetition (see the last few lines of the explanation below).
i= # send i (index) to...
[* # convert to array (splat)...
[
(t=Time.new).month, # the current month...
t.day,t.hour,t.min,t.sec # etc... (duh)
]
.each_cons(2) # each consecutive two elements
] # [[month, day], [day, hour], [hour, min], etc]
.index [3,14]; # first occurrence of [3, 14]
i&& # shorthand for "if i"...
$><< # output...
[
'Pi Day', # [month=3, day=14] is Pi Day
'', # [day=3, hour=14] isn't anything
'Pi Minute', # [hour=3, min=14] is Pi Minute
'Pi Second' # [min=3, sec=14] is Pi Second
][i] # index by index (obviously)
Python 2, 219 186 183 Bytes (198-15)
I tried
Ungolfed:
from datetime import datetime
now = datetime.now()
output = ['Pi Day', 'Pi Minute', 'Pi Second', 'No Pi Time']
if now.month == 3 and now.day == 14:
print output[0]
elif now.hour == 2 and now.minute == 13:
print output[1]
elif now.minute = 2 and now.second == 13:
print output[2]
else:
print output[3]
Golfed:
from datetime import *
n=datetime.now()
a=n.minute
if n.month==3and n.day==14:print'Pi Day'
elif n.hour==2and a==13:print'Pi Minute'
elif a==2and n.second==13:print'Pi Second'
else:print'No Pi Time'