RE: time, calendar, datetime, etc

Discussion in 'Python' started by Tim Peters, Aug 3, 2003.

  1. Tim Peters

    Tim Peters Guest

    [Dan Bishop]
    > There were no leap years between 10 BC and AD 4, because after Julius
    > Caesar's death, the priests in charge of the calendar mistakenly added
    > leap days every 3 years instead of 4, and this had to be corrected.
    >
    > I wouldn't expect the datetime module to deal with that, though ;-)


    Thank you -- some people did <wink>.


    > ...
    > >>> datetime.date(1970, 8, 22).weekday()

    > 5
    > >>> datetime.date(6970, 8, 22).weekday()

    > 5
    >
    > The output above is my least favorite feature of the datetime module.
    > It took me a while to figure out that those dates are Saturdays.


    That's very peculiar! Because they're not both Saturdays:

    >>> datetime.date(1970, 8, 22).weekday()

    5
    >>> datetime.date(6970, 8, 22).weekday()

    2
    >>>


    Or if you want names instead:

    >>> datetime.date(1970, 8, 22).ctime()[:3]

    'Sat'
    >>> datetime.date(6970, 8, 22).ctime()[:3]

    'Wed'
    >>>


    Did you actually run the example you pasted, or just assume that the second
    line would display 5 too, or didn't paste the actual example you ran and
    made a typo?

    The earlier claim:

    > The Gregorian leap year cycle is 400 years and this is coincidentally
    > also a whole number of weeks.


    was correct, but the 5000 years between 1970 and 6970 isn't a multiple of
    400, so the example as given wasn't relevant to that claim.

    > Perhaps we could add a weekday class to 2.3.1?
    >
    > DAY_NAMES = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
    > 'Saturday', 'Sunday']
    > class weekday(int):
    > def __repr__(self):
    > return DAY_NAMES[self]
    > for i, name in enumerate(DAY_NAMES):
    > globals()[name] = weekday(i)


    I doubt anything like this will get added, in part because we have the
    unfortunate fact that .weekday() and .isoweekday() map day names into little
    integers differently. As shown above, you can easily get English day names
    (well, abbreviations) from the .ctime() result. A .strftime() format works
    too, except .strftime() has irritating year-range limitations inherited from
    C.

    I have a little dateutil.py module I use for my own stuff, containing

    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7)

    (JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE,
    JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER) = range(1, 13)

    at the start. That's easy, and caters to that (1) I'm unlikely ever to use
    ..isoweekday(); and, (2) after decades of practice, I'm comfortable with the
    English names for these things. It's much easier to do something similar
    for yourself than to try to define a gimmick that covers the union of all
    peoples' crazy ideas <wink>.
    Tim Peters, Aug 3, 2003
    #1
    1. Advertising

  2. Tim Peters

    Andrew Dalke Guest

    Aahz:
    > Pick any standard Unix reader: trn3.6, trn4, slrn, tin, pine, gnus, ...


    I *like* GUI-based email and usenet programs.

    (And unlike you, I find lynx to be a confusing browser. Eg,
    when there are two links, side-by-side, I keep pressing
    the right arrow key to go from the left to the right, which
    lynx hears as "descend into the current link.")

    Andrew
    Andrew Dalke, Aug 3, 2003
    #2
    1. Advertising

  3. Tim Peters

    John Roth Guest

    "Tim Peters" <> wrote in message
    news:...
    > [Dan Bishop]
    > > There were no leap years between 10 BC and AD 4, because after Julius
    > > Caesar's death, the priests in charge of the calendar mistakenly added
    > > leap days every 3 years instead of 4, and this had to be corrected.
    > >
    > > I wouldn't expect the datetime module to deal with that, though ;-)

    >
    > Thank you -- some people did <wink>.


    I don't think I noticed that: the entire point behind the proleptic
    calender is that you're projecting the current practice back to
    times where they weren't doing it that way.

    That's clearly an opportunity for someone to add an extension -
    except that there are other problems in that era, and the lack
    of leap years is the least of them.

    John Roth
    >
    >
    > > ...
    > > >>> datetime.date(1970, 8, 22).weekday()

    > > 5
    > > >>> datetime.date(6970, 8, 22).weekday()

    > > 5
    > >
    > > The output above is my least favorite feature of the datetime module.
    > > It took me a while to figure out that those dates are Saturdays.

    >
    > That's very peculiar! Because they're not both Saturdays:
    >
    > >>> datetime.date(1970, 8, 22).weekday()

    > 5
    > >>> datetime.date(6970, 8, 22).weekday()

    > 2
    > >>>

    >
    > Or if you want names instead:
    >
    > >>> datetime.date(1970, 8, 22).ctime()[:3]

    > 'Sat'
    > >>> datetime.date(6970, 8, 22).ctime()[:3]

    > 'Wed'
    > >>>

    >
    > Did you actually run the example you pasted, or just assume that the

    second
    > line would display 5 too, or didn't paste the actual example you ran and
    > made a typo?
    >
    > The earlier claim:
    >
    > > The Gregorian leap year cycle is 400 years and this is coincidentally
    > > also a whole number of weeks.

    >
    > was correct, but the 5000 years between 1970 and 6970 isn't a multiple of
    > 400, so the example as given wasn't relevant to that claim.
    >
    > > Perhaps we could add a weekday class to 2.3.1?
    > >
    > > DAY_NAMES = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
    > > 'Saturday', 'Sunday']
    > > class weekday(int):
    > > def __repr__(self):
    > > return DAY_NAMES[self]
    > > for i, name in enumerate(DAY_NAMES):
    > > globals()[name] = weekday(i)

    >
    > I doubt anything like this will get added, in part because we have the
    > unfortunate fact that .weekday() and .isoweekday() map day names into

    little
    > integers differently. As shown above, you can easily get English day

    names
    > (well, abbreviations) from the .ctime() result. A .strftime() format

    works
    > too, except .strftime() has irritating year-range limitations inherited

    from
    > C.
    >
    > I have a little dateutil.py module I use for my own stuff, containing
    >
    > MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7)
    >
    > (JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE,
    > JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER) = range(1, 13)
    >
    > at the start. That's easy, and caters to that (1) I'm unlikely ever to

    use
    > .isoweekday(); and, (2) after decades of practice, I'm comfortable with

    the
    > English names for these things. It's much easier to do something similar
    > for yourself than to try to define a gimmick that covers the union of all
    > peoples' crazy ideas <wink>.
    >
    >
    John Roth, Aug 4, 2003
    #3
  4. Tim Peters

    John Baxter Guest

    In article <>,
    "Tim Peters" <> wrote:

    > [Dan Bishop]
    > > There were no leap years between 10 BC and AD 4, because after Julius
    > > Caesar's death, the priests in charge of the calendar mistakenly added
    > > leap days every 3 years instead of 4, and this had to be corrected.
    > >
    > > I wouldn't expect the datetime module to deal with that, though ;-)

    >
    > Thank you -- some people did <wink>.


    One interesting bit of reading about this stuff comes from the nice
    folks at
    http://www.wundermoosen.com

    (in fact, I see they've put out some more calendar white papers,
    including "How we figured out the Viking calendar.")

    Look under Calendar X for the Viking calendar paper, "The Mayan
    Calendar" and some others.

    The paper I was thinking of when I started this is around here
    somewhere, but I don't immediately see it on the site. It was referred
    to by (shipped with?) Calendar2000. It includes a good view of when
    various countries switched from Julian to Gregorian (and in at least one
    case switched back and switched again).

    --John
    John Baxter, Aug 5, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben S
    Replies:
    16
    Views:
    726
    John Roth
    Aug 4, 2003
  2. Ben S
    Replies:
    2
    Views:
    303
    Steven Taschuk
    Aug 1, 2003
  3. Tim Peters

    RE: time, calendar, datetime, etc

    Tim Peters, Aug 2, 2003, in forum: Python
    Replies:
    3
    Views:
    296
    John Roth
    Aug 3, 2003
  4. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    685
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  5. Tim Peters
    Replies:
    0
    Views:
    517
    Tim Peters
    Sep 9, 2003
Loading...

Share This Page