[Question]
  [
Inspired by [We had a unit test once which only failed on Sundays](https://qntm.org/unit), 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](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest bytecount in each language wins!
I'll have to wait til Sunday to check the answers ;)
  
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + coreutils, ~~15~~ 14 bytes
```
`date|grep Su`
```
[Try it online!](https://tio.run/##S0oszvhfoKGpoFFQlJlXkqagrpoUk6dqoFUak6euoKTioKRQo1BSpGCgoKtgp2akycVVoBDi7@IYqWD6PyElsSS1Jr0otUAhuDThf4GCekyen2tEiEJwqB9QhbqCoSEXWI2CbkpxaV5KYiVcMcgYmGpffwzVufkoqv8DAA "Bash – Try It Online")
[Answer]
# PHP 7, 12 bytes
```
1%date("w");
```
On PHP 7 it throws an exception of type [`DivisionByZero`](http://php.net/manual/en/class.divisionbyzeroerror.php) on Sundays. The same happens if it is interpreted using [HHVM](https://en.wikipedia.org/wiki/HHVM).
On PHP 5 it displays a warning (on `stderr`) on Sundays:
```
PHP Warning:  Division by zero in Command line code on line 1
```
On any PHP version, it doesn't display anything on the other days of the week.
Run using the CLI:
```
php -r '1%date("w");'
```
or [try it online!](https://3v4l.org/IXe7i)
Two more bytes can be squeezed by stripping the quotes (`1%date(w);`) but this triggers a notice (that can be suppressed by properly set [`error_reporting = E_ALL & ~E_NOTICE`](http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting) in `php.ini`).
[Answer]
# Java 8, ~~69~~ ~~43~~ 34 bytes
```
v->1/new java.util.Date().getDay()
```
-26 bytes thanks to *@OlivierGrégoire*.  
-9 bytes thanks to *@Neil*.
**Explanation:**
[Try it here.](https://tio.run/##LY0xD4IwEIV3f8WN7UCNM9GJVRYTFuNwlkqK9SD0WmMMv70WIbk33Eu@9/UYsRhGQ337TNqh93BGS98dgCU20wO1gXp5/wVo0Qy2hSjLXM05@TwjWw01EBwhxeJ02JN5Q5@nVWDrVIVshFSd4Qo/QqZy5cZwd5nb8LjsvrJbXHiy1F1vKFcvKS0oOLc55/QD)
* `v->{...}` ([unused `Void` `null` parameter](https://codegolf.meta.stackexchange.com/questions/12681/are-we-allowed-to-use-empty-input-we-wont-use-when-no-input-is-asked-regarding)) is one byte shorter than `()->{...}` (no parameter).
* `new java.util.Date().getDay()` will return 0-6 for Sunday-Saturday, so `1/...` will give an `java.lang.ArithmeticException: / by zero` error if the value is 0, which only happens on Sundays.
[Answer]
# PHP, 15 bytes
```
<?@date(w)?:\n;
```
Assumes [default settings](https://codegolf.meta.stackexchange.com/a/1670).
**Output on Sundays**
```
Fatal error: Undefined constant 'n' on line 1
```
[Try it online!](https://tio.run/##K8go@P/fxt4hJbEkVaNc094qJs/6//9/@QUlmfl5xf918wA "PHP – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 33 bytes
```
import time
"Su"in time.ctime()>q
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PzO3IL@oRKEkMzeVSym4VCkzD8zWSwaRGpp2hf//AwA "Python 3 – Try It Online")
# [Python 3](https://docs.python.org/3/), 50 bytes
```
from datetime import*
datetime.now().weekday()>5>q
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P60oP1chJbEktSQzN1UhM7cgv6hEiwsmoJeXX66hqVeempqdklipoWlnalf4/z8A "Python 3 – Try It Online")
Saved ~3 bytes thanks to [Rod](https://codegolf.stackexchange.com/users/47120/rod).
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~8~~ 7 bytes
```
 l-6.d9
```
[Try it online!](https://tio.run/##K6gsyfj/XyFH10wvxfL/fwA "Pyth – Try It Online")
Explanation 
```
    .d9 # Get the current day of week (0 = Monday, 6 = Sunday)
  -6    # Subtract 6 from the day
 l      # Try to calculate the log base 2 of the result of the previous operation raising a "ValueError: math domain error" on sundays
        # there is an extra space at the start, to supress the output on the other days
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~45~~ 44 bytes
As 05AB1E doesn't have a built in for getting the day of the week, I've used Zeller's Rule to calculate it. 
Prints a newline to stderr in case of a Sunday (observable in the debug view on TIO)
```
žežf11+14%Ì13*5÷žgžf3‹-т%D4÷žgт÷©4÷®·(O7%i.ǝ
```
[Try it online!](https://tio.run/##MzBNTDJM/f//6L7Uo/vSDA21DU1UD/cYGmuZHt5@dF86UMz4UcNO3YtNqi4mYJGLTYe3H1oJZB9ad2i7hr@5aqbe8bn//wMA "05AB1E – Try It Online")
**Explanation**
The general formula used is  
`DoW = d + [(13*(m+1))/5] + y + [y/4] + [c/4] - 2*c`  
Where `DoW=day of week`, `d=day`, `m=month`, `y=last 2 digits of year`, `c=century` and and expression in brackets (`[]`) is rounded down.
Each month used in the formula correspond to a number, where `Jan=13,Feb=14,Mar=3,...,Dec=12`  
As we have the current month in the more common format `Jan=1,...,Dec=12`
we convert the month using the formula  
`m = (m0 + 11) % 14 + 1`
As a biproduct of March being the first month, **January** and **February** belong to the previous year, so the calculation for determining `y` becomes  
`y = (year - (m0 < 3)) % 100`
The final value for `DoW` we get is an int where `0=Sat,1=Sun,...,6=Fri`.  
Now we can explicitly throw an error if the result is true.
[Answer]
# JavaScript, 23 Bytes
```
Date().slice(1)>'um'&&k
```
Full program.
The variable `k` must not be defined.
# JavaScript, 20 bytes by Rick Hitchcock
```
/Su/.test(Date())&&k
```
# JavaScript, 19 bytes by apsillers
```
Date().match`Su`&&k
```
[Answer]
## Ruby, 15 bytes
```
1/Time.now.wday
```
`wday` will return 0 on Sunday causing a ZeroDivisionError: divided by 0 error. For example: `1/Time.new(2018,1,7).wday`. 
[Answer]
# [Haskell](https://www.haskell.org/) + [Data.Dates](https://hackage.haskell.org/package/dates-0.2.2.1/docs/Data-Dates.html), 55 bytes
```
import Data.Dates
succ.dateWeekDay<$>getCurrentDateTime
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRD0ikFnPlJmbm2RaUFqWqKBaXJifrpQBFw1NTs10SK21U7NJTS5xLi4pS80pAqkMyc1P//wcA "Haskell – Try It Online") 
This uses the fact that Sunday is the last day of the week. `dateWeekDay` returns the day of the week as a `WeekDay` type, which is simply defined as
```
data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
```
`WeekDay` is an instance of `Enum`, thus we can use `succ` and `pred` to get the successor or predecessor of a weekday, e.g. `succ Monday` yields `Tuesday`.
However, `Sunday` is the last enum entry, so calling `succ Sunday` results in the following error:
```
fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates
```
*Edit 1: Thanks to nimi for -3 bytes!*  
*Edit 2: -11 bytes now that functions are allowed.*
---
### Full program: ~~88~~ ~~81~~ ~~74~~ ~~69~~ 66 bytes
```
import Data.Dates
main=pure$!succ.dateWeekDay<$>getCurrentDateTime
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRD0ikFnPlJmbm2RaUFqWqKBaXJifrpQBFw1NTs10SK21U7NJTS5xLi4pS80pAqkMyc1P//wcA "Haskell – Try It Online")
`pure` is needed to lift the resulting `WeekDay` back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why `$!` is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.
---
### Previous approach with `Data.Time`: ~~127~~ 124 bytes
```
import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay
```
[Try it online!](https://tio.run/##Zcu9CoMwEADgPU9hoYOC3OrSuOgjFDrKkRw15E/Oy1Dou6d2cHL94Ftx9xRCrS5umaWZURCeLhJMIRuvroyBkkWGF5E/mJRpl37pbfe1j0FbFdEl/SaZCjMl@adx1O1WmO63DgxIPisUMTLjp9Yf) These are some impressive imports. Change `d<7` to e.g. `d/=5` to test failure on a Friday. Fails with the following exception: `Non-exhaustive patterns in function c`.
[Answer]
# [Perl 5](https://www.perl.org/), 13 bytes
```
1/(gmtime)[6]
```
[Try it online!](https://tio.run/##K0gtyjH9/99QXyM9tyQzN1Uz2iz2/38A "Perl 5 – Try It Online")
Ported @biketire's answerj
*removed 3 bytes with @mik's reminder*
[Answer]
# VBA / VBScript, ~~22~~ 20 bytes
Saved 2 bytes thanks to Taylor Scott.
```
a=1/(Weekday(Now)-1)
```
This should be run in the Immediate Window. `Weekday()` returns 1 (Sunday) through 7 (Saturday) so this creates a divide by zero error on Sunday. Otherwise, no output.
[![Error Message](https://i.stack.imgur.com/tGlOX.png)](https://i.stack.imgur.com/tGlOX.png)
[Answer]
# TI-Basic 84+, 23 bytes
```
getDate
0/(1-dayOfWk(Ans(1),Ans(2),Ans(3
```
Needs date & time commands, which are 84+ and higher only.
[Answer]
## C, 35, 34 27 bytes
```
f(n){n/=time(0)/86400%7^3;}
```
-7 bytes with thanks to @MartinEnder and @Dennis
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOk/ftiQzN1XDQFPfwszEwEDVPM7YuvZ/Zl6JQm5iZp6GJlc1lwIQpGloWoMZBUVAuTQNJZfMlDz1EoXkosTiDD0loGTtfwA)
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `O`, 25 bytes
```
kðtD4/‟₀/N‟:400/kτṠ7%2<[←
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=O&code=k%C3%B0tD4%2F%E2%80%9F%E2%82%80%2FN%E2%80%9F%3A400%2Fk%CF%84%E1%B9%A07%252%3C%5B%E2%86%90&inputs=&header=&footer=)
Vyxal doesn't have a weekday function, so I made one myself.
[Answer]
# [R](https://www.r-project.org/), ~~31 bytes~~ 30 bytes
```
if(format(Sys.Date(),'%u')>6)a
```
[Try it online!](https://tio.run/##K/r/PzNNIy2/KDexRCO4sljPJbEkVUNTR121VF3T1tZcM/H/fwA)
No output on non-Sundays, `Error: object 'a' not found` on Sundays.
`format(Sys.Date(),'%u')` was the shortest way I could find to get weekday, it outputs a character-class number for day of week, with 7 for Sundays. We can compare to a numeric 7, and if true attempt to use an undefined object. 
Saved a byte thanks to Giuseppe!
[Answer]
# [Zsh](https://www.zsh.org) `-G`, 14 bytes
```
>`date`
dd Su*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjWbSSrrtS7M1gZYXSvOT83NzUvBKFkozMYoWczLxUhZJ8hdLiVIVEhbTE7FSFlMSSVCsuZTCtoWljY6MeXJqnYGik4J9comBgZmVgaWVipOAUHKJgZGBkqL60tCRN12KdXQJIfQJXSopCcKkWRHABlILSAA)
* `date`: get the date in the format `Sun 28 Mar 07:55:54 BST 2021`
* `>`: create a file named according to each of the words in the output
* `dd`: "copy and convert" - here it basically does nothing
	+ this command expects no arguments
* `Su*`: search for a file starting with `Su`
	+ if a file matching that exists (which happens when it is Sunday), then it is passed to `dd`
		- since `dd` expects no arguments, this produces an error
	+ with the `-G` option: if no file matches (i.e. it is not Sunday), don't error as usual
This produces a bit of extra junk output to STDERR (not an error though) which may or may not be allowed; the question isn't really clear. Here's an alternative answer which doesn't:
## [Zsh](https://www.zsh.org) `-G`, 18 bytes
```
>`date`
mv <-> Su*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjWbSSrrtS7M1gZYXSvOT83NzUvBKFkozMYoWczLxUhZJ8hdLiVIVEhbTE7FSFlMSSVCsuZTCtoWljY6MeXJqnYGik4J9comBgZmVgaWVipOAUHKJgZGBkqL60tCRN12KTXQJIfQJXbpmCja6dQnCpFkRiAZSC0gA)
`<->` matches any file whose name is a number, of which there are two: the day of the month, and the year.
When there is no `Su*` file, this is renames the day of the month to the year (overwriting the year), which works fine.
When `Sun` exists, it tries to move the day of the month and the year into the directory `Sun`, which fails because `Sun` is a file, not a directory.
[Answer]
# jq, 42 characters
(39 characters code + 3 characters command line option)
```
now|strftime("%w")|strptime("%d")|empty
```
Just trying a different approach here: parse week day number (0..6) as month day number (1..31).
Sample run:
```
bash-4.4$ TZ=UTC faketime 2018-01-06 jq -n 'now|strftime("%w")|strptime("%d")|empty'
bash-4.4$ TZ=UTC faketime 2018-01-07 jq -n 'now|strftime("%w")|strptime("%d")|empty'
jq: error (at <unknown>): date "0" does not match format "%d"
```
Note that jq only handles UTC dates.
[Try it online!](https://tio.run/##yyr8/z8vv7ymuKQorSQzN1VDSbVcSRPELYByU4Dc1NyCksr////r5gEA "jq – Try It Online")
[Answer]
# ***Q, 20 Bytes***
```
if[1=.z.d mod 7;'e]
```
.z.d returns the current date. mod does the modulo of the current date, which returns an int. If the date is a sunday, .z.d mod 7 returns 1.
 If 1=1, (on sunday), and error is raised using the ' operator
For brevity the error is just the e character.
[Answer]
# [Julia 0.6](http://julialang.org/), 32 bytes
Thanks to @Dennis for pointing out `<` saves a byte over `!=`.
```
@assert Dates.dayofweek(now())<7
```
[Try it online!](https://tio.run/##yyrNyUw0@//fIbG4OLWoRMElsSS1WC8lsTI/rTw1NVsjL79cQ1PTxvz/fwA "Julia 0.6 – Try It Online")
[Answer]
## VBA 18 bytes
This relies on the inbuilt function `date()` returning a day number that remainders 1 if divided by 7, so may be OS and/or CPU specific.
```
a=1/(date mod 7-1)
```
It runs in the VBA project Immediate window. 
[Answer]
# C, ~~68~~ 55 bytes
*Thanks to @Ken Y-N for saving 13 bytes!*
```
#import<time.h>
f(n){time(&n);n/=gmtime(&n)->tm_wday;;}
```
[Try it online!](https://tio.run/##S9ZNT07@/185M7cgv6jEpiQzN1Uvw44rTSNPsxrE0VDL07TO07dNz4XxdO1KcuPLUxIrra1r/2fmlSjkJmbmaWhyVXMpAEGahqY1mFFQBJRL01ByyUzJUy9RSC5KLM7QUwJK1v4HAA)
[Answer]
# [MATL](https://github.com/lmendo/MATL), 12 bytes
```
vZ'8XOs309>)
```
The error produced on Sundays is:
* Interpreter running on Octave:
```
MATL run-time error: The following Octave error refers to statement number 9:  )
---
array(1): out of bound 0
```
* Interpreter running on Matlab:
```
MATL run-time error: The following MATLAB error refers to statement number 9:  )
---
Index exceeds matrix dimensions
```
To invert behaviour (error on any day except on Sundays), add `~` after `>`.
[**Try it Online!**](https://tio.run/##y00syfn/vyxK3SLCv9jYwNJO8/9/AA)
### Explanation
This exploits the fact that
* indexing into an empty array with the logical index `false` is valid (and the result is an empty array, which produces no output); whereas
* indexing with `true` causes an error because the array lacks a first entry.
Commented code:
```
v       % Concatenate stack. Gives empty array
Z'      % Push current date and time as a number
8XO     % Convert to date string with format 8: gives 'Mon', 'Tue' etc
s       % Sum of ASCII codes. Gives 310 for 'Sun', and less for others
309>    % Greater than 309? Gives true for 'Sun', false for others
)       % Index into the empty array
        % Implicit display. Empty arrays are not displayed (not even newline)
```
[Answer]
# Excel, 24
Closing quote and paren not counted toward final score, as Excel will autocorrect both of those. Tested in Excel 2016.
```
=IF(MOD(TODAY()-1,7)^0,"")
```
I think this is different from the [other submission](https://codegolf.stackexchange.com/a/152775/91403) enough to warrant another answer.
### How it works:
* I've rolled the error into the conditional check. As it turns out, `TODAY()` mod 7 also gives the weekday. If it's a Sunday, this means that `MOD(TODAY()-1,7)` is `0`, and `0^0` is an error in Excel.
	+ Of course, I could also have divided `1` by the `MOD()` value or used `+6` instead of `-1`.
* If it's not Sunday, the `MOD(...,7)` will be non-zero, which when raised to `0`, returns `1`, a truthy value. This makes the `IF` return an empty string (our "nothing").
* The if statement, therefore, cannot evaluate to `FALSE`, because it errors or returns nothing.
### Alternative
Here's one that works just as well, but uses a Name error instead:
```
=IF(MOD(TODAY(),7)=1,A,"")
```
[Answer]
# TI-Basic, ~~22~~ 21 bytes
```
getDate
log(log(dayOfWk(Ans(1),Ans(2),Ans(3
```
-1 byte by using [MarcMush](https://codegolf.stackexchange.com/users/98541/marcmush)'s method but replacing `ln(` with `log(`.
Only works on TI-84+/SE. Assumes that the date is set correctly before the program is run. There is a newline at the end.
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 23 bytes
```
⎕CY'dfns'
o←÷7|⌊days⎕TS
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKM97f@jvqnOkeopaXnF6lz5j9omHN5uXvOopyslsbIYKBUSDFL1Pw0A "APL (Dyalog Unicode) – Try It Online")
[Answer]
## Ocaml, 46 bytes
```
open Unix
let()=1/(gmtime(time())).tm_wday;()
```
and in the ocaml REPL, we can achieve better by removing the `let` and the final `:()`:
```
$ open Unix;;1/(gmtime(time())).tm_wday;;<CR>
```
which is 41 bytes (incuding 1 byte for the carriage return).
[Answer]
## SAS, 36 bytes
```
%put %eval(1/(1-%index(&sysday,Su)))
```
[Answer]
# [Julia 0.5](http://julialang.org/), 28 bytes
```
Dates.dayofweek(now())<7||~-
```
[Try it online!](https://tio.run/##PcwxCkIxEATQ/p9i@DYJqJ2ksfQGeoGAK0bDbtjNJwgfrx6DguUMb@ax5BQPvZ9iJdtf40tujejpWJrz/hjW9b3rRRPXzG6@yBBIBpaK88IjzX6aws9hg/8BlOqibAgQhn2pbVHvY2ycSqGKmNsoQaqi1j8 "Julia 0.5 – Try It Online")
This does *not* work with 0.6, but it does with 0.4.
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/learn/what-is-dotnet), 55 54 48 bytes
[Try it online!](https://tio.run/##TY7NDoIwEITvfYo9wkHUc4XE6NG/qIlHU@tiVqCNtGAI4dlrQaPObeZLZkaakdQlusqQusGhMRYLzv5dtCL14IzJXBgDO9Yy8DJWWJJQa7rCWpAKwiF@w15zaUmrmb7cUdoE0kpJiN05TtpalJDF03FAyoafjaWweKQCo41@etNs0xNixjvHv4V9QzAJf8FCK6NzjPYorv4jBp4NsGOdewE)
*Saved 1 byte thanks to Shaggy*
*Saved 5 byte thanks to Emigna*
*Saved 1 byte thanks to Kevin Cruijssen*
```
_=>{var k=1/(int)System.DateTime.Now.DayOfWeek;}
```
Lucky that Sunday is indexed 0 in enum or else it would've needed to be `(System.DayOfWeek)7`
]