Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #18601

Re: Date/Calendar confusion

Received by 10.66.82.195 with SMTP id k3mr1472841pay.23.1347068670481; Fri, 07 Sep 2012 18:44:30 -0700 (PDT)
Received by 10.68.232.9 with SMTP id tk9mr1876167pbc.0.1347068670464; Fri, 07 Sep 2012 18:44:30 -0700 (PDT)
Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!news.snarked.org!newsfeed.news.ucla.edu!usenet.stanford.edu!r4no6314207pbs.0!news-out.google.com!a8ni11616485pbd.1!nntp.google.com!r4no6314205pbs.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.programmer
Date Fri, 7 Sep 2012 18:44:30 -0700 (PDT)
In-Reply-To <nospam-64D325.21022107092012@news.aioe.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
NNTP-Posting-Host 69.28.149.29
References <3a69eb4a-f3c0-4b56-9a67-6833ccb2a1c8@googlegroups.com> <nospam-D06BA0.20534806092012@news.aioe.org> <3931f4ca-a41a-489a-8521-545eaed21742@googlegroups.com> <nospam-64D325.21022107092012@news.aioe.org>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <816d0737-3c2e-476a-9a56-41a13964fe5a@googlegroups.com> (permalink)
Subject Re: Date/Calendar confusion
From Lew <lewbloch@gmail.com>
Injection-Date Sat, 08 Sep 2012 01:44:30 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.lang.java.programmer:18601

Show key headers only | View raw


John B. Matthews wrote:
> Lew wrote:
>>  John B. Matthews wrote:
>>> Ulrich Scholz  wrote:
> 
> [Valuable clarifications elided.]
> 
>>>     calendar2.set(Calendar.YEAR, 1970);
>>>     calendar2.set(Calendar.MONTH, Calendar.JANUARY);
>>>     calendar2.set(Calendar.DAY_OF_MONTH, 1);
>>> 
>>>     calendar2.clear(Calendar.HOUR);
>> 
>> Better: 'calendar2.set(Calendar.HOUR, 0);'
> 
> Can I impose on you to amplify further? Is this related to "the 
> resolution rule for the time of day," mentioned in clear(int)?
> 
> <http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#time_resolution>
> <http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#clear(int)>

I guess, but that's not my focus. My focus is on the fact that when you 'clear(int)', as opposed
to 'set(int,int)', the 'Calendar' instance does no reconciliation, nor can you rely on any specific 
field value such as '0'. 'clear()' sets fields to *undefined*, not a specific value. It makes no 
attempt to reconcile field values, e.g., to set a day to a valid value based on the month value
or vice versa.

So you have no promise as to what the values are after a 'clear()'. What comes out might well
surprise, as it did on that project some years ago where I encountered this situation.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Date/Calendar confusion Ulrich Scholz <d7@thispla.net> - 2012-09-06 01:03 -0700
  Re: Date/Calendar confusion nogales <nogales.manuel@gmail.com> - 2012-09-06 02:29 -0700
  Re: Date/Calendar confusion Lew <lewbloch@gmail.com> - 2012-09-06 10:21 -0700
  Re: Date/Calendar confusion "John B. Matthews" <nospam@nospam.invalid> - 2012-09-06 20:53 -0400
    Re: Date/Calendar confusion Lew <lewbloch@gmail.com> - 2012-09-07 11:01 -0700
      Re: Date/Calendar confusion "John B. Matthews" <nospam@nospam.invalid> - 2012-09-07 21:02 -0400
        Re: Date/Calendar confusion Lew <lewbloch@gmail.com> - 2012-09-07 18:44 -0700
          Re: Date/Calendar confusion "John B. Matthews" <nospam@nospam.invalid> - 2012-09-08 09:12 -0400
            Re: Date/Calendar confusion Lew <lewbloch@gmail.com> - 2012-09-08 16:51 -0700

csiph-web