124

Day-of-week: Allowed range 0 – 7. Sunday is either 0 or 7.

I found this after Googling, my question is why should both values (0,7) correspond to Sunday?

7
  • 17
    I think that a logical think some country start the week the monday and some other on sunday so puting the sunday first and last resolve this misunderstanding I guess
    – Kiwy
    Dec 20, 2013 at 8:55
  • 13
    Because sunday is such an awsome day, don't you agree? :P
    – Alko
    Dec 20, 2013 at 13:13
  • 4
    Because Americans think Sunday is the first day of the week, but Europeans say Sunday is the last day of the week.
    – Pieter B
    Dec 20, 2013 at 15:16
  • 10
    Don't forget about Funday.
    – MDMoore313
    Dec 20, 2013 at 16:02
  • 8
    Because by the seventh day, God completed His work which He had done, and He rested on the seventh day from all His work which He had done.
    – user84207
    Jul 18, 2014 at 16:56

4 Answers 4

138

This is a matter of portability. In early Unices, some versions of cron accepted 0 as Sunday, and some accepted 7 as Sunday -- this format is an attempt to be portable with both. From man 5 crontab in vixie-cron (emphasis my own):

When specifying day of week, both day 0 and day 7 will be considered Sunday. BSD and AT&T seem to disagree about this.

12
  • 45
    There are 10 kinds of people, those who start counting with 0 and those who start with 1. Dec 20, 2013 at 13:17
  • 37
    @HagenvonEitzen I remember the joke differently: There are 10 kinds of people, those who understand binary and those who don't. -- Also: There are 2 kinds of people: (1.) those who start counting with 1, (1.) those who start with 0.
    – leemes
    Dec 20, 2013 at 13:49
  • 7
    I have another version - there are three kinds of people in the world - those that can count and those that cant.
    – flurbius
    Dec 20, 2013 at 14:59
  • 28
    Or: There are two types of people. Those that can extrapolate from incomplete data.
    – Bernhard
    Dec 20, 2013 at 15:14
  • 23
    Or: There are 10 types of people in the world - those who understand Gray code, those who don't and those who expected a joke about binary.
    – OnoSendai
    Dec 20, 2013 at 15:22
28

In addition to @ChrisDown's excellent answer, this might also be a nifty solution to a localisation issue: "According to the Hebrew calendars and traditional Christian calendars, Sunday is the first day of the week." Having it both ways, which is really easy programmatically, makes it easy to use for either group.

4
  • Kudos, for your support @l0b0 Dec 20, 2013 at 9:21
  • 5
    +1, good answer. I assume this is the reason why AT&T and BSD didn't agree :-)
    – Chris Down
    Dec 20, 2013 at 9:31
  • :) hope so heh heh ;) Dec 20, 2013 at 9:34
  • Note that for this to work, you also need to mentally change whether you start your counting at 0 or at 1. There is less need to make this distinction when the focus is on whether Sunday is the first or last day of the week, as phrased in this answer. Mar 19, 2021 at 21:16
3

There is widespread disagreement as to which day of the week makes sense to be considered the first.

Historically, our seven-day week comes from Genesis, in both the Hebrew Bible and the Christian Bible. But our modern lifestyle with Saturday and Sunday being considered "the weekend" obscures this, and makes it easy to think of Sunday as the last day instead of the first day.

Some natural languages actually encode the perspective of Sunday-as first-day or Sunday-as-last-day into their vocabulary, using ordinal names for some of the days, with Serbian and Portuguese being two examples. In Serbian, Petak means 5th day, but refers to Friday. In Portuguese, sexta-feira means 6th day, but refers to Friday.

In apps I use, some treat Sunday as the first day and others as the last day. Most calendar apps seem to allow the user to configure this, but not all apps do that.

The compromise made by cron is quite clever, actually, allowing some users to have their preference as long as they are willing to use a 0-based array, and others to have theirs as long as they are willing to use a 1-based array.

2

More simply, the field is 3 binary bits giving you 000 through 111 or 0 through 7. So there are a total of eight values in a 3 bit field. The extra value is equated to the first so, for convenience sake, you can start at 0 (Sunday) or 1 (Monday), increment 6 times and cover a full week.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.