14
\$\begingroup\$

SE will be down/read only today 2017-05-04 at 00:00 UTC until 00:20 UTC.

Your challenge is to output a truthy value if SE is down/read only and a falsy value if SE is not. You may not have any input, and you must use date builtins to determine if SE is down/read only (no actually querying the SE api!) Example output:

12:34 UTC 03 May 2017 -> false

00:00 UTC 04 May 2017 -> true

00:20 UTC 20 May 2017 -> undefined, see below

That's undefined behavior, because it's too far after the window of time. To be clear, you can assume your program will be run from UTC 8:00 today (5/3/17) to UTC 1:00 tomorrow (5/4/17).

00:21 UTC 04 May 2017 -> false

00:20 UTC 04 May 2017 -> true

00:10 UTC 04 May 2017 -> true

Note that any truthy or falsy values are allowed, not just true and false. You must be accurate to the nearest second, and no changing the system clock! You may assume that your program is being run on a machine on the +0 UTC time zone.

\$\endgroup\$
14
  • 8
    \$\begingroup\$ sudo time <insert time here> && echo true \$\endgroup\$
    – Okx
    Commented May 3, 2017 at 10:47
  • 8
    \$\begingroup\$ I'd suggest updating the test cases to use a universal date format rather than American. \$\endgroup\$
    – Shaggy
    Commented May 3, 2017 at 11:08
  • 12
    \$\begingroup\$ Step #1, trigger bot army to DDoS SE, Step #2, return "1" \$\endgroup\$ Commented May 3, 2017 at 15:06
  • 9
    \$\begingroup\$ First, as the SO SRE Manager, I want to say that I love this question. Good work! However, I do want to remind people that the site won't be hard down... just in read-only mode. That said, I will be selecting on answer to this question to help me determine when to start the procedure. \$\endgroup\$
    – TomOnTime
    Commented May 3, 2017 at 15:19
  • 3
    \$\begingroup\$ That would mean your own answer is invalid, no? So would many other answers; neither your original revision nor the current test cases mention seconds. \$\endgroup\$
    – Dennis
    Commented May 4, 2017 at 14:07

18 Answers 18

15
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ Save 2 bytes by using new Date instead of new Date(). \$\endgroup\$
    – Shaggy
    Commented May 3, 2017 at 11:10
  • \$\begingroup\$ <2 to save another byte. \$\endgroup\$
    – Shaggy
    Commented May 3, 2017 at 11:14
  • 1
    \$\begingroup\$ You don't need the +; / automatically converts new Date to a Number. \$\endgroup\$
    – Luke
    Commented May 3, 2017 at 12:00
  • \$\begingroup\$ Is the function declaration (_=>) needed? JavaScript can run globally. \$\endgroup\$
    – Brilliand
    Commented May 3, 2017 at 20:32
  • \$\begingroup\$ @Brilliand Yes, otherwise output would be needed, the shortest being alert which is a lot longer \$\endgroup\$
    – ASCII-only
    Commented May 3, 2017 at 21:37
14
\$\begingroup\$

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?

Try it online!

\$\endgroup\$
0
8
\$\begingroup\$

Python 2, 41 39 bytes

Saved 2 bytes thanks to Erik the Outgolfer

import time
print time.time()/1200%72<1

Try it online!

Uses the same algorithm as my JS and Charcoal answers.

\$\endgroup\$
6
  • \$\begingroup\$ Is /72<1 different from <72? \$\endgroup\$
    – xnor
    Commented May 3, 2017 at 21:02
  • \$\begingroup\$ @xnor whoops sorry copied it wrong, fixed now \$\endgroup\$
    – ASCII-only
    Commented May 3, 2017 at 21:36
  • \$\begingroup\$ No, I mean that I think print time.time()/1200<72 would be a shorter way to express the same thing. \$\endgroup\$
    – xnor
    Commented May 4, 2017 at 0:52
  • \$\begingroup\$ @xnor I'm pretty sure that only works on the first day of the epoch though \$\endgroup\$
    – ASCII-only
    Commented May 4, 2017 at 1:26
  • \$\begingroup\$ Oops, I meant %1200/72<1 -> %1200<72. Your TIO links to the %1200/72<1 version -- is that a mistake? \$\endgroup\$
    – xnor
    Commented May 4, 2017 at 1:28
6
\$\begingroup\$

Jelly, 9 bytes

6ŒT|0Ḍ<21

Requires TZ to be set to UTC, which is the case for TIO.

Try it online!

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.
\$\endgroup\$
3
  • \$\begingroup\$ (Everyone was) Outgolfed by Dennis! Nice job! \$\endgroup\$
    – user58826
    Commented May 3, 2017 at 12:24
  • 1
    \$\begingroup\$ Not everyone... \$\endgroup\$
    – Dennis
    Commented May 3, 2017 at 12:37
  • \$\begingroup\$ If the downtime latest 'til 00:21, I could save a byte... \$\endgroup\$
    – Dennis
    Commented May 3, 2017 at 12:56
5
\$\begingroup\$

Japt, 32 11 bytes

K/12e5%72<1

Try it online!

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

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.

\$\endgroup\$
6
  • \$\begingroup\$ Save 2 bytes by using new Date instead of new Date(). \$\endgroup\$
    – Shaggy
    Commented May 3, 2017 at 10:56
  • 2
    \$\begingroup\$ -1 this doesn't check the date \$\endgroup\$
    – ASCII-only
    Commented May 3, 2017 at 10:57
  • \$\begingroup\$ @ASCII-only the question says it dosen't have to. \$\endgroup\$
    – user58826
    Commented May 3, 2017 at 10:58
  • \$\begingroup\$ Save another byte with y=>(x=new Date).getUTCMinutes()<21&&!x.getUTCHours(). \$\endgroup\$
    – Shaggy
    Commented May 3, 2017 at 10:58
  • 1
    \$\begingroup\$ Save another 6 bytes by using local time instead of UTC - the question says you may assume local time is UTC. \$\endgroup\$
    – Brilliand
    Commented May 3, 2017 at 20:15
3
\$\begingroup\$

zsh, 38 37 bytes:

date +%H\ %M|read h m;((h==0&&m<21))
\$\endgroup\$
0
3
\$\begingroup\$

bash, 40 bytes:

read h m< <(date +%H\ %M);((h==0&&m<21))
\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ What character is the ? \$\endgroup\$
    – user58826
    Commented May 3, 2017 at 11:24
  • \$\begingroup\$ @programmer5000 (Quad) is a prefix for system names in APL. It is supposed to be an empty rectangle. \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 11:26
2
\$\begingroup\$

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

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ What does the ⟦⟧ do here? Do you need a list or arrowlist literal? \$\endgroup\$ Commented May 3, 2017 at 11:59
  • \$\begingroup\$ Yeah, a list is required here, but now that I think about it I should make it optional \$\endgroup\$
    – ASCII-only
    Commented May 3, 2017 at 11:59
  • \$\begingroup\$ Oh, so it's a list of arguments? Yeah, you should make it optional, calling the function without arguments by default. \$\endgroup\$ Commented May 3, 2017 at 12:00
  • \$\begingroup\$ @EriktheOutgolfer Done \$\endgroup\$
    – ASCII-only
    Commented May 3, 2017 at 21:36
2
\$\begingroup\$

Alice, 17 bytes

/o
\T@/4&;'-.C+n

Try it online!

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.
\$\endgroup\$
2
\$\begingroup\$

MATL, 10 bytes

Thanks to Dennis for several corrections

Z'1\480*7<

Try it online!

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. 
\$\endgroup\$
8
  • \$\begingroup\$ Should that be l72 rather than 171 in your explanation? \$\endgroup\$
    – Dennis
    Commented May 3, 2017 at 13:38
  • \$\begingroup\$ @Dennis Yes, thanks for catching that! \$\endgroup\$
    – Luis Mendo
    Commented May 3, 2017 at 13:39
  • \$\begingroup\$ It's still 72 vs 71. Also wouldn't this return 0 at 00:20? \$\endgroup\$
    – Dennis
    Commented May 3, 2017 at 13:42
  • \$\begingroup\$ @Dennis Yes, this would return 0 at 00:20, but would return 1 at 00:20 minus a small fraction of a second (given by the machine epsilon for double data type times 86400). The challenge says "you must be accurate to the nearest minute", so I understand it's acceptable \$\endgroup\$
    – Luis Mendo
    Commented May 3, 2017 at 13:47
  • \$\begingroup\$ That's probably what the post on Mother Meta meant, but the challenge has 00:20 -> true as a test case. Left a comment on the question. \$\endgroup\$
    – Dennis
    Commented May 3, 2017 at 13:50
2
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ You can save a whole bunch of bytes by using a different format string, and if you're using the shell, you don't need the print function: import time;e=str(time.strftime('%H:%M'));e[:2]=='00'and int(e[2:])<21. This can probably be golfed even further too. \$\endgroup\$
    – Bahrom
    Commented May 3, 2017 at 21:02
  • \$\begingroup\$ (pretty new to golfing and the rules) but in the shell this also seems to output the correct results: import time;time.localtime();_.tm_hour==0 and _.tm_min<21. We're not beating ASCII-only anyway lol \$\endgroup\$
    – Bahrom
    Commented May 3, 2017 at 21:11
  • \$\begingroup\$ Ok, I cannot edit now, maybe later \$\endgroup\$
    – Mr. Xcoder
    Commented May 4, 2017 at 4:44
1
\$\begingroup\$

Pyth, 11 bytes

&g20.d7!.d6

Online interpreter link

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

Bash, 55 53 51 50 bytes

-1 byte from @robbie0630's comment.

a=`date +%s`;echo $[1493856000<a&a<1493857200?1:0]

Try it online!

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).

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Shave off a byte by replacing $(...) with `...` \$\endgroup\$
    – robbie
    Commented May 4, 2017 at 0:53
0
\$\begingroup\$

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.

\$\endgroup\$
0
0
\$\begingroup\$

R, 65 bytes

library(lubridate)
x=Sys.time()
print(all(!hour(x)&minute(x)<21))

Checks if the hour == 0 and the minute < 21.

\$\endgroup\$
0
\$\begingroup\$

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)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.