# We Had A Question Once Which Only Failed On Sundays

Inspired by We had a unit test once which only failed on Sundays, write a program or function that does nothing but throw an error when it is Sunday, and exit gracefully on any other day.

### Rules:

• No using input or showing output through the usual IO methods, except to print to STDERR or your language's equivalent. You are allowed to print to STDOUT if it's a by-product of your error.
• A function may return a value on non-Sundays as long as it doesn't print anything
• Your program may use a Sunday from any timezone, or the local timezone, as long as it is consistent.
• An error is a something that makes the program terminate abnormally, such as a divide by zero error or using an uninitialised variable. This means that if any code were to be added after the part that errors, it would not be executed on Sunday.
• You can also use statements that manually create an error, equivalent to Python’s raise.
• This includes runtime errors, syntax errors and errors while compiling (good luck with that!)
• On an error there must be some sign that distinguishes it from having no error
• This is , so the shortest bytecount in each language wins!

I'll have to wait til Sunday to check the answers ;)

• By "write a program or function that does nothing but throw an error on Sunday, and exit gracefully on any other day", do you mean that whenever it is run on sunday it should fail, or do you mean that there should be at least one possibility it fails a sunday. To make it clearer, if it fails only on sunday at 2pm, but not on sunday 3pm, is it fine ? – Bromind Jan 5 '18 at 13:53
• This would have been even better if Saturday had been used. You could have called it "Saturday Night Error" and even worked in some adjusted song lyrics to the question. – Aaron Jan 5 '18 at 18:57
• Sundays? How about failing between midnight and 1am? – Draco18s Jan 5 '18 at 20:25
• It's not clear from your question what constitutes an error. I'm voting to close until this is remedied. – Sriotchilism O'Zaic Jan 6 '18 at 16:28
• Not really ... How can we distinguish the output of an error from regular output. Is something like print "error" an error? The added paragraph doesn't really clarify anything. – Sriotchilism O'Zaic Jan 6 '18 at 18:20

# Julia 0.6, 32 bytes

Thanks to @Dennis for pointing out < saves a byte over !=.

@assert Dates.dayofweek(now())<7


Try it online!

# Pure bash BASH (interactive mode + no coreutils required), 1720 19 bytes

PS1='((1/\D{%w}))&&:'


# Now only 19 bytes thanks to manatwork's comment below.

Bonus, if you put it in your bashrc it fails every sunday you log in :-) not just when you run it on sundays!

• Nice, but on non-Sunday days should output nothing. – manatwork Jan 5 '18 at 21:29
• now it outputs nothing on non sundays. – Ahmed Masud Jan 5 '18 at 21:52
• You can save 1 character using professorfish's tip. – manatwork Jan 5 '18 at 22:16
• You should mark this as Bash REPL, as this won't fail in a Bash script/full program. – Dennis Jan 5 '18 at 23:42

# Excel, 77 30 bytes

Yes, vastly more golfable.

=IF(WEEKDAY(TODAY())=1,1/0,"")


Simply checks if it's Sunday, and if so, finds the quickest way I know of to error. If not Sunday, returns "",the closest Excel has to not returning anything

# C# (.NET Core), 3943 41 bytes

_=>{if(1/(int)DateTime.Now.DayOfWeek<0);}


Try it online!

Thanks to @caird coinheringaahing and @Jo King

• Welcome to the site! You can remove the leading newline in your answer to save one byte. Also, it seems as though this is a snippet, rather than a program or a function. If this is the case, you can prepend a _=> to make it a valid submission. – caird coinheringaahing Jan 8 '18 at 7:58
• @caird coinheringaahing - Is it allowed to have a warning like i currently have? – SirTaphos Jan 8 '18 at 13:04
• It should be, but I would ask under the question, so that the author can decide. – caird coinheringaahing Jan 8 '18 at 16:08
• A warning is fine. Could you also use <0 instead of ==-1 to save 2 bytes? – Jo King Jan 10 '18 at 5:48
• Yes I could, good idea, thanks! – SirTaphos Jan 10 '18 at 9:52

Postgresql, 32

Not sure if you need to add ; at the end for valid answer

SELECT 1/EXTRACT(DOW FROM now())


# Zsh, 15 bytes

${(%):-%(w._.)}  Try it online! Prompt sequences can be really crazy sometimes... ${(%):-%(w._.)}
${(%) } # expand as prompt sequence :- #${var:-fallback}, but without the var
%( . .)    # Prompt ternary
w        # If DoW matches given number (implied 0, which is Sunday)
._      # Then substitute _
.     # Else substitute nothing


Since _ is not a command, it fails on Sunday.

# SmileBASIC, 20 bytes

DTREAD OUT,,,W
W=W/W


DTREAD outputs the current year, month, day, and day of the week. Sunday is 0.

# Java 8, 34 bytes

Returns 1 on Mondays, 0 on other days, and throws an ArithmeticException on Sundays

v->1/new java.util.Date().getDay()


Try it online!

## Batch, 88 bytes

@for /f "skip=1" %%d in ('wmic path win32_localtime get dayofweek')do @set/a1/%%d&exit/b


Tries to divide by zero on Sunday.

Unfortunately neither date nor powershell date work on my PC to give me the day of the week.

## PowerShell, 24 20 Bytes

1/(date).DayOfWeek>1


Sunday triggers divide by zero same as most of the other solution here. Problem is that on other days that a double gets returned so redirect to nowhere useful trumps that output.

# Swift 4, 78 bytes

import Foundation;if(Calendar.current.component(.day,from:Date()))==7{exit(1)}


Try it online!

# AWK, 272523 21 bytes

END{1/strftime("%w")}


Try it online!

Saved 4 bytes thanks to manatwork

Saved 2 bytes thanks to mik

• But strftime() also handles “%w The day of the week as a decimal, range 0 to 6, Sunday being 0.”, according to man 3 strftime. – manatwork Jan 5 '18 at 17:17
• Ok, but now you can remove the outer parenthesis too. – manatwork Jan 5 '18 at 17:21
• Whoops, thats what i get for rushing – Noskcaj Jan 5 '18 at 17:24
• END instead of BEGIN will also work – mik Jan 6 '18 at 15:30

# Octave, 23 22 bytes

(1:6)(weekday(now)-1);


Try it online!

This will try to access an element in 1:6. When the day is Sunday it will try to access the element (1-1)=(0) which will result in an error as MATLAB is 1-indexed.

Original for 23.

assert(weekday(now)~=1)


Try it online!

assert(...) will throw an error when the condition is false. weekday(now) returns the current day of the week where 1 = Sunday. Put the two together, the code will throw an error only on sundays when the condition becomes 1~=1.

# Clojure, 43 bytes

#(and(=(.getDay(java.util.Date.))7)(/ 1 0))


Try it online!

Uses the fact that and doesn't evaluate the second argument unless necessary. I originally thought I could get away with using the Ratio literal 1/0 to save two bytes, but that unfortunately causes exceptions immediately. It must try to reduce the Ratio right away or something.

(defn sunday-fail []
(and (= (.getDay (Date.)) 7)
(/ 1 0)))