| Bytes | Lang | Time | Link |
|---|---|---|---|
| 093 | Pascal | 250504T000002Z | Kai Burg |
| 077 | Python 3 NONREPL + time | 170503T114649Z | Mr. Xcod |
| 043 | PostgreSQL | 170504T145340Z | manatwor |
| 065 | R | 170504T143117Z | BLT |
| 050 | Bash | 170503T153906Z | DimP |
| 039 | Python 2 | 170503T115532Z | ASCII-on |
| 010 | MATL | 170503T131635Z | Luis Men |
| 017 | Alice | 170503T173424Z | Martin E |
| 008 | 05AB1E | 170503T105639Z | Okx |
| 009 | Jelly | 170503T120756Z | Dennis |
| 021 | JavaScript ES6 | 170503T110723Z | ASCII-on |
| 178 | Swift + Foundation | 170503T113806Z | Mr. Xcod |
| 025 | Charcoal | 170503T114820Z | ASCII-on |
| 011 | Japt | 170503T114733Z | Luke |
| 011 | Pyth | 170503T113740Z | Erik the |
| 040 | bash | 170503T112913Z | Thor |
| 037 | zsh | 170503T111822Z | Thor |
| 014 | APL Dyalog | 170503T111957Z | Adá |
| 049 | JS ES6 | 170503T105407Z | user5882 |
Pascal, 93 B
This complete program requires a processor supporting features of Extended Pascal as defined by ISO standard 10206, in particular the time‐related functionality.
Furthermore, the implementation‐defined notion of the value getTimeStamp populates a timeStamp needs to represent the real‐time clock.
program t(output);var t:timeStamp;begin
getTimeStamp(t);write((t.hour=0)and(t.minute<20))end.
In a production program you are of course supposed to verify (timeStamp.dateValid and) timeStamp.timeValid, too.
Should you not have a space‐time‐travel machine at hand, you can test the program by setting the date on POSIX™‐compliant platforms with
date 201705040000 # run as superuser and then start the program as normal user
Python 3 (NON-REPL) + time, 81 77 bytes
-4 bytes thanks to Bahrom
import time;e=str(time.strftime('%H:%M'));print(e[:2]=='00'and int(e[3:])<21)
A naïve approach, turning the current date to string and analysing its characters.
PostgreSQL, 43 characters
select now()between'170503'and'170503 0:20'
Just because I prefer SQL for date/time calculations.
Sample run:
bash-4.3$ psql -c "select now()between'170503'and'170503 0:20'"
?column?
----------
f
(1 row)
R, 65 bytes
library(lubridate)
x=Sys.time()
print(all(!hour(x)&minute(x)<21))
Checks if the hour == 0 and the minute < 21.
Bash, 55 53 51 50 bytes
-1 byte from @robbie0630's comment.
a=`date +%s`;echo $[1493856000<a&a<1493857200?1:0]
The advantage of this solution is that it works for any date (so will return 1 only for the period defined in the challenge, as it uses epoch time).
Python 2, 41 39 bytes
Saved 2 bytes thanks to Erik the Outgolfer
import time
print time.time()/1200%72<1
Uses the same algorithm as my JS and Charcoal answers.
MATL, 10 bytes
Thanks to Dennis for several corrections
Z'1\480*7<
Explanation
Z' % Push current date and time as a float. Integer part is day, decimal part is time
1\ % Modulo 1. This gives the time, in units of one day
480* % Multiply by 480
7< % Less than 7? Note that 21 minutes / one day equals 7 / 480. Implicitly display.
Alice, 17 bytes
/o
\T@/4&;'-.C+n
Assumes to be run on a machine whose timezone is set to UTC (like the TIO server).
Explanation
While in Ordinal mode, the IP bounces diagonally up and down through the program. While in Cardinal mode, the IP wraps around the edges like most other Fungeoids.
/ Reflect to SE. Switch to Ordinal.
T Push a string representing the current date and time, in the format:
YYYY-MM-DDTHH:MM:SS.mmm±AA:BB
/ Reflect to E. Switch to Cardinal.
4& Run the next command 4 times.
; Discard four elements from the top of the stack. Since we're in Cardinal mode,
this attempts to discard four integers. But the top stack value is a string so
it gets implicitly converted to all the integers contained in the string. So
year, month, day, hour, minute, seconds, milliseconds, timezone hour,
timezone minute will be pushed separately. Then the last four of these
will be discarded, so that we end up with the minute and the hour on
top of the stack.
' Push 21.
- Subtract it from the minutes. Gives something negative for minutes 0 to 20.
.C Compute the binomial coefficient n-choose-n. This gives 0 for negative
results and 1 for non-negative ones. SE is down if both this value and
the current hour are zero.
+ Add the two values. Iff they are both zero, we still get a zero.
n Logical NOT of the value. Turns 0 into 1 and everything else into 0.
\ Reflect to NE. Switch to Ordinal.
o Implicitly convert the result to a string and print it.
@ Terminate the program.
05AB1E, 32 26 11 9 8 bytes
žažb«21‹
Explanation:
ža Is the current hour &
žb current minute
« concatenated
‹ less than
21 twenty one?
Jelly, 9 bytes
6ŒT|0Ḍ<21
Requires TZ to be set to UTC, which is the case for TIO.
How it works
6ŒT|0Ḍ<21 Main link. No arguments.
6ŒT Get the current time as a string, in the format HH:MM.
|0 Bitwise OR each character with 0. This casts the characters to int and
maps the non-digit character : to 0.
Ḍ Undecimal; convert from base 10 to integer.
<21 Compare the result with 21, so 00:00 to 00:20 return 1, all others
return 0.
JavaScript (ES6), 26 24 23 22 21 bytes
Saved 3 bytes thanks to Shaggy and 1 byte thanks to Luke.
_=>new Date/12e5%72<1
Checks if time passed in current day is less than 1200000ms (1200s or 20min). Assumes downtime to be 20 minutes not 21, which appears to be the case in the linked post. 00:20UTC is the exclusive upper bound.
Swift + Foundation, 178 bytes
import Foundation;var d=String(describing:Date());func g(_ s:Int)->String{return String(d[d.index(d.startIndex,offsetBy:s)])};print(g(11)+g(12)=="00" ?Int(g(14)+g(15))!<21:false)
Quite short by swift standards. Check it out!
As in my Python answer, I basically converted the current Date to a string and have analysed its digits, depending on which I printed the bool.
Charcoal, 25 bytes
‹﹪÷UPtime.time⟦⟧¹²⁰⁰¦⁷²¦¹
Prints - for truthy, nothing for falsy.
Explanation
UPtime.time⟦⟧ Python function time.time()
÷ ¹²⁰⁰ Divided by 1200
﹪ ¦⁷² Modulo 72
‹ ¦¹ Less than 1
bash, 40 bytes:
read h m< <(date +%H\ %M);((h==0&&m<21))
zsh, 38 37 bytes:
date +%H\ %M|read h m;((h==0&&m<21))
APL (Dyalog), 14 bytes
∧/1 20>2↑3↓⎕TS
∧/ is it all-true (AND reduction) that
1 20> these numbers are greater than
2↑ the first two elements of
3↓⎕TS the current Time Stamp with three elements dropped
JS (ES6), 52 50 49 bytes
y=>(x=new Date).getUTCMinutes()<21&&!x.getUTCHours()
Why is Date so long? Just gets the minutes past 00:00 and returns true if they are < 21, and false otherwise.