Haskell + Data.Dates, 88 81 74 69 6655 bytes
import Data.Dates
main=pure$!succ.dateWeekDay<$>getCurrentDateTime
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
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.
Edit: Thanks to nimi for -3 bytes!
Haskell, 127 124 bytes
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! 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
.