Re: date + 90 days

Discussion in 'Java' started by Roedy Green, Jul 30, 2003.

  1. Roedy Green

    Roedy Green Guest

    On Wed, 30 Jul 2003 22:32:53 +0200, "[XaToA]"
    <> wrote or quoted :

    >how can i sum to ahora 90 days?


    extract the long timestamp. add 90 days worth of milliseconds,
    i.e. 90L * 24 * 60 * 60 * 1000

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jul 30, 2003
    #1
    1. Advertising

  2. Roedy Green

    Jacob Guest

    Roedy Green wrote:
    > On Wed, 30 Jul 2003 22:32:53 +0200, "[XaToA]"
    > <> wrote or quoted :
    >
    >
    >>how can i sum to ahora 90 days?

    >
    >
    > extract the long timestamp. add 90 days worth of milliseconds,
    > i.e. 90L * 24 * 60 * 60 * 1000


    The problem with Date is that it's not what
    it claims to be; A date. (It's a *time*).
    The above senseless (but of course correct)
    construct proves the erroneous design.

    Why is there no java.util.Time? It could
    inherit from (a timeless) Date and add the
    time-of-day as it's specific feature.

    I've created my own date class where time
    is non-existent and day arithmetics are
    made simple.
     
    Jacob, Aug 11, 2003
    #2
    1. Advertising

  3. Roedy Green

    Roedy Green Guest

    On Mon, 11 Aug 2003 11:39:22 +0200, Jacob <> wrote or
    quoted :

    >The problem with Date is that it's not what
    >it claims to be; A date. (It's a *time*).
    >The above senseless (but of course correct)
    >construct proves the erroneous design.


    If you want a pure date without the gotchas, see
    http://mindprod.com/jgloss/bigdate.html

    Some guy used it for tracking satellites and then added a time
    component to it. However he did not give me that code back.

    Calendar is not as goofy as Date was, but it still has its oddnesses,
    and it carries quite a bit of baggage.

    The main problem with Date and Calendar is they MAKE you deal with
    time and timezones even when they are irrelevant, e.g. what date is
    Easter this year?

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Aug 14, 2003
    #3
  4. Roedy Green <> writes:
    > The main problem with Date and Calendar is they MAKE you deal with
    > time and timezones even when they are irrelevant, e.g. what date is
    > Easter this year?


    Orthodox or catholic? They are different. Date, times and calendars are
    not as easy as it looks at first glance. In the case of Eastern the
    date even depends on your believes.

    If you want to have some fun, have a look at the timezone definition
    files for Unix (e.g. ftp://elsie.nci.nih.gov/pub/tzdata2003a.tar.gz).
    It is amazing how people have messed around with times and offsets. You
    will find historic timezone offsets like -5:36:20.

    /Thomas
     
    Thomas Weidenfeller, Aug 14, 2003
    #4
  5. Roedy Green

    Roedy Green Guest

    On Thu, 14 Aug 2003 06:28:16 +0000 (UTC), lid
    (Thomas Weidenfeller) wrote or quoted :

    >It is amazing how people have messed around with times and offsets. You
    >will find historic timezone offsets like -5:36:20.


    I met a composer in Edmonton who was a railroad buff. He believed
    that daylight saving was evil. He refused to change his clocks. Over
    the years I have come to believe was right. Daylight saving is a goofy
    idea. It leads to too many anomalies and complications.

    You can't even specify local time unambiguously. I bet there are bugs
    in many payroll programs around switchover. Think of the screwups that
    happen in missing appointments and travel on switchover days.

    Switchover causes accidents. It would make more sense to just move
    office hours earlier in the day ALL the time.

    Someone pointed out Brazil implemented DST, removed it, then
    instituted it again, blowing Sun's generic specification scheme.

    DST was originally called War time in the US, and the offset was as
    much as five hours in some communities.

    What was that strange -5:36:20 example?



    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Aug 14, 2003
    #5
  6. Roedy Green

    Jacob Guest

    Thomas Weidenfeller wrote:
    > Roedy Green <> writes:
    >
    >>The main problem with Date and Calendar is they MAKE you deal with
    >>time and timezones even when they are irrelevant, e.g. what date is
    >>Easter this year?

    >
    >
    > Orthodox or catholic? They are different. Date, times and calendars are
    > not as easy as it looks at first glance. In the case of Eastern the
    > date even depends on your believes.
    >
    > If you want to have some fun, have a look at the timezone definition
    > files for Unix (e.g. ftp://elsie.nci.nih.gov/pub/tzdata2003a.tar.gz).
    > It is amazing how people have messed around with times and offsets. You
    > will find historic timezone offsets like -5:36:20.


    Yes. calendars are complex, but no, most programs shouldn't
    care. From any possible example, Roady choose a very bad one
    bringing religion into the matter... :)

    What you normally need (99.9% of the time) is a simple way to
    bundle year/month/day plus some methods to compare dates and
    do date arithmetics.

    I've implemented a Day.java that does this, and I'll pass it
    on to anyone interested.
     
    Jacob, Aug 14, 2003
    #6
  7. Roedy Green

    Roedy Green Guest

    On Thu, 14 Aug 2003 10:06:18 +0200, Jacob <> wrote or
    quoted :

    >Yes. calendars are complex, but no, most programs shouldn't
    >care. From any possible example, Roady choose a very bad one
    >bringing religion into the matter... :)



    I just wanted to pick a date that moved around so the question has
    some substance. How about Canadian labour day?

    I have written a set of classes to computed dozens of possible
    holidays. See http://mindprod.com/jgloss/holidaycalculator.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Aug 14, 2003
    #7
  8. =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Aug 14, 2003
    #8
  9. Roedy Green

    WB Guest

    Thomas Weidenfeller wrote:
    > My #1 rule when dealing with date/time: Store everythng in UTC. If
    > necessary, store a time-zone indicator with the data to support display
    > of local time at the place of origin of the data. Use the long timezone
    > names (not the three or four letter abbreviations, they aren't
    > unique). Leave displaying local time to the GUI.


    I do too, except for storing the local time-zone. The JavaScript date
    object only returns the offset in minutes (which Calendar can "add" to
    the UTC to get the local time). How do you determine the TimeZone from
    the client?


    However, retrieving a Date from a UTC Calendar object, actually returns
    the date for the local TimeZone:
    ----------------------------------
    TimeZone tzHere = TimeZone.getDefault();
    TimeZone tzGMT = TimeZone.getTimeZone("Etc/Greenwich");

    Calendar calHere = Calendar.getInstance(tzHere);
    Calendar calGMT = Calendar.getInstance(tzGMT);

    Date dtHere = calHere.getTime();
    Date dtGMT = calGMT.getTime();

    System.out.println("Here Date: " + dtHere.toString() );
    System.out.println("GMT Date: " + dtGMT.toString() );

    System.out.println("Here Hour: " + calHere.get(Calendar.HOUR_OF_DAY) );
    System.out.println("GMT Hour: " + calGMT.get(Calendar.HOUR_OF_DAY) );
    ----------------------------------
    will print:
    ----------------------------------
    Here Date: Thu Aug 14 08:06:31 PDT 2003
    GMT Date: Thu Aug 14 08:06:31 PDT 2003
    Here Hour: 8
    GMT Hour: 15
    ----------------------------------
    Uh oh, that's not right! The Date objects for both UTC and local hold
    the same date/time, yet extracting the hour directly from the Calendar
    objects gives the correct hours.

    Yet the documentation reads (v 1.4.1):
    ----------------------------------
    public final Date getTime()

    Gets this Calendar's current time.
    ----------------------------------
     
    WB, Aug 14, 2003
    #9
  10. Roedy Green

    Jacob Guest

    Thomas Weidenfeller wrote:

    > My #1 rule when dealing with date/time: Store everythng in UTC. If
    > necessary, store a time-zone indicator with the data to support display
    > of local time at the place of origin of the data. Use the long timezone
    > names (not the three or four letter abbreviations, they aren't
    > unique). Leave displaying local time to the GUI.


    Agree! But you talk about *time*. A *date* is
    a lot simpler, at least in any normal case.

    Sun adds a lot of confusion to this matter
    since they mix calendar/date/time into a
    single Calendar class. The calendar class is
    a bright idea, but why does it refer to a
    specific instance in time? And why does the
    Date class include reference to time? And
    where is the Time class?

    Without thinking deeply into it, I'd suggest
    the Calendar as the base entity, much as it
    is now, but witout its specific time reference.
    Next is a time-less Date class referring to a
    given Calendar, and at the bottom, a Time
    class inheriting from the Date class adding
    the time part.
     
    Jacob, Aug 14, 2003
    #10
  11. Roedy Green

    Roedy Green Guest

    Roedy Green, Aug 14, 2003
    #11
  12. WB <> writes:
    > I do too, except for storing the local time-zone. The JavaScript date


    I will ignore the mentioning of JavaScr*pt for the moment :)

    > object only returns the offset in minutes (which Calendar can "add" to
    > the UTC to get the local time). How do you determine the TimeZone from
    > the client?



    I didn't express myself too clear. I have two applications that are
    supposed to communicate with each other (online or offline). What I do
    is to think in two categories:

    Origin of the information which I want to mark/stamp with some time
    information, and

    Representation of that information, which can happen at a totally
    different place.

    At time and place of origin I use UTC-based time information. The
    simplest in Java is to use Date.getTime() and store that long as-is. Or
    you format the long using SimpleDateFormat and specify GMT as time zone
    for the format (which looks better than the long when stored in log
    files). Plus, I stor a textual(!) representation of the time zone name
    of the place of origin. You get one with TimeZone.getDisplayName(). Of
    course, you don't have to store that name for every time/date value,
    but e.g. only once for a log file.

    The time zone at place-of-origin is just for display purposes. Which
    leads to the display of the data at some other place: I treat this as a
    GUI issue (responsibility of the View in MVC terms). If necessary I can
    display the information in any of the following three forms:

    Local time at place of origin
    Local time at place of display
    UTC/GMT

    /Thomas
     
    Thomas Weidenfeller, Aug 15, 2003
    #12
  13. Roedy Green

    Roedy Green Guest

    On Fri, 15 Aug 2003 20:09:58 GMT, WB <> wrote or
    quoted :

    >To know the Alberta user's time zone, I need to get the machines time
    >zone. I can either ask the user to select it (via some option screen) or
    >I can dynamically get it (for which I use JavaScript).


    Can you explain why the default Applet timezone is not sufficient? Is
    it just that Win users often don't configure their machines correctly?
    What is JavaScript doing?

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Aug 15, 2003
    #13
    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. David Stockwell
    Replies:
    2
    Views:
    703
    Anna Martelli Ravenscroft
    Sep 20, 2004
  2. Gerrit
    Replies:
    0
    Views:
    386
    Gerrit
    Sep 20, 2004
  3. Terry Reedy
    Replies:
    0
    Views:
    430
    Terry Reedy
    Sep 20, 2004
  4. Replies:
    5
    Views:
    470
    Bo Yang
    Nov 2, 2006
  5. kirke

    list of days between two days

    kirke, Oct 19, 2006, in forum: Javascript
    Replies:
    7
    Views:
    138
    Julian Turner
    Oct 20, 2006
Loading...

Share This Page