DST Start date

Discussion in 'Java' started by Roedy Green, Oct 3, 2009.

  1. Roedy Green

    Roedy Green Guest

    Is there a simpler way to find out when DST starts in a given year
    than stepping through the year day by day calling
    TimeZone.inDaylightTime( Date )?
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    When you can’t find a bug, you are probably looking in the wrong place. When you can’t find your glasses, you don’t keep scanning the same spot because you are convinced that is where you left them.
    ~ Roedy
     
    Roedy Green, Oct 3, 2009
    #1
    1. Advertising

  2. Roedy Green

    Arne Vajhøj Guest

    Roedy Green wrote:
    > Is there a simpler way to find out when DST starts in a given year
    > than stepping through the year day by day calling
    > TimeZone.inDaylightTime( Date )?


    No, that information is private in the SimpleTimeZone class.

    Arne
     
    Arne Vajhøj, Oct 3, 2009
    #2
    1. Advertising

  3. Roedy Green

    Eric Sosman Guest

    Roedy Green wrote:
    > Is there a simpler way to find out when DST starts in a given year
    > than stepping through the year day by day calling
    > TimeZone.inDaylightTime( Date )?


    "Simpler?" Probably not. "Quicker?" Well, you could
    do a kind of binary search, starting with the assumption that
    DST begins in the first half of the year. 7 < lg(183) < 8.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Oct 4, 2009
    #3
  4. Roedy Green

    Roedy Green Guest

    On Sat, 03 Oct 2009 21:48:51 -0400, Eric Sosman
    <> wrote, quoted or indirectly quoted
    someone who said :

    >
    > "Simpler?" Probably not. "Quicker?" Well, you could
    >do a kind of binary search, starting with the assumption that
    >DST begins in the first half of the year. 7 < lg(183) < 8.


    There is the complication of the southern hemisphere. In this case
    speed is not a concern.

    code is posted at
    https://wush.net/websvn/mindprod/fi...om/mindprod/holidays/DaylightSavingStart.java
    https://wush.net/websvn/mindprod/fi.../com/mindprod/holidays/DaylightSavingEnd.java

    It is a bit cryptic. It fits into a template for describing holidays
    in general. It uses BigDate.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    When you can’t find a bug, you are probably looking in the wrong place. When you can’t find your glasses, you don’t keep scanning the same spot because you are convinced that is where you left them.
    ~ Roedy
     
    Roedy Green, Oct 4, 2009
    #4
  5. In article <4ac7cb44$0$290$>,
    Arne Vajhøj <> wrote:

    > Roedy Green wrote:
    > > Is there a simpler way to find out when DST starts in a given year
    > > than stepping through the year day by day calling
    > > TimeZone.inDaylightTime( Date )?

    >
    > No, that information is private in the SimpleTimeZone class.


    This is correct, but one can examine the values in the private
    simpleTimeZoneParams array of sun.util.calendar.ZoneInfo. The number and
    meaning of the parameters are a function of which SimpleTimeZone
    constructor was used to create the ZoneInfo, as described here:

    <http://www.docjar.com/html/api/sun/util/calendar/ZoneInfo.java.html>

    <method>
    private static void printTzParams (String id) {
    TimeZone tz = TimeZone.getTimeZone(id);
    String name = "simpleTimeZoneParams";
    final Field fields[] = tz.getClass().getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
    if (name.equals(fields.getName())) {
    try {
    fields.setAccessible(true);
    int[] ia = (int[]) fields.get(tz);
    System.out.print("Params for "
    + tz.getID() + ": ");
    for (int j = 0; j < ia.length; j++) {
    System.out.print(ia[j] + " ");
    }
    System.out.println();
    }
    catch (IllegalAccessException e) {
    System.err.println("IllegalAccess: " + name);
    }
    }
    }
    }
    </method>

    <example>
    Params for Europe/London: 2 -1 1 3600000 2 9 -1 1 3600000 2
    Params for Europe/Zurich: 2 -1 1 3600000 2 9 -1 1 3600000 2
    Params for US/Eastern: 2 8 -1 7200000 10 1 -1 7200000
    Params for US/Pacific: 2 8 -1 7200000 10 1 -1 7200000
    </example>

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Oct 4, 2009
    #5
  6. In comp.lang.java.programmer message <ha8uu5$jtq$-
    september.org>, Sat, 3 Oct 2009 21:48:51, Eric Sosman <esosman@ieee-dot-
    org.invalid> posted:
    >Roedy Green wrote:
    >> Is there a simpler way to find out when DST starts in a given year
    >> than stepping through the year day by day calling
    >> TimeZone.inDaylightTime( Date )?

    >
    > "Simpler?" Probably not. "Quicker?" Well, you could
    >do a kind of binary search, starting with the assumption that
    >DST begins in the first half of the year. 7 < lg(183) < 8.


    I do similar, in JavaScript, calling the misnamed getTimezoneOffset(),
    in <URL:http://www.merlyn.demon.co.uk/js-date5.htm> and its include
    files, to get the change to the nearest few seconds then rounded to the
    minute. Call it first for January 1 and July 1; if they are the same,
    there's no Summer time; if they differ the sign tells the hemisphere.

    It may be unwise, though, to assume that the apparent time status only
    changes twice a year in all locations and all systems. At least one
    JavaScript browser makes six changes per year, outside 1970 to 2038.

    --
    (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
    Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
    PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
    Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
     
    Dr J R Stockton, Oct 4, 2009
    #6
  7. Roedy Green

    Roedy Green Guest

    On Sun, 04 Oct 2009 01:28:52 -0400, "John B. Matthews"
    <> wrote, quoted or indirectly quoted someone who
    said :

    >
    >This is correct, but one can examine the values in the private
    >simpleTimeZoneParams array of sun.util.calendar.ZoneInfo. The number and
    >meaning of the parameters are a function of which SimpleTimeZone
    >constructor was used to create the ZoneInfo, as described here:


    Was the idea to make the timezone info table driven, but leave a hole
    open in case there were ever a case the table scheme could not handle?
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    Smart data structures and dumb code works a lot better than the other way around.
    ~ Eric S. Raymond The Cathedral and the Bazaar
     
    Roedy Green, Oct 5, 2009
    #7
  8. Roedy Green

    Roedy Green Guest

    On Sun, 4 Oct 2009 20:17:20 +0100, Dr J R Stockton
    <> wrote, quoted or indirectly quoted
    someone who said :

    >At least one
    >JavaScript browser makes six changes per year, outside 1970 to 2038.


    What timezone is that?
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    Smart data structures and dumb code works a lot better than the other way around.
    ~ Eric S. Raymond The Cathedral and the Bazaar
     
    Roedy Green, Oct 5, 2009
    #8
  9. In article <>,
    Roedy Green <> wrote:

    > On Sun, 04 Oct 2009 01:28:52 -0400, "John B. Matthews"
    > <> wrote, quoted or indirectly quoted someone who
    > said :
    >
    > >
    > >This is correct, but one can examine the values in the private
    > >simpleTimeZoneParams array of sun.util.calendar.ZoneInfo. The number and
    > >meaning of the parameters are a function of which SimpleTimeZone
    > >constructor was used to create the ZoneInfo, as described here:

    >
    > Was the idea to make the timezone info table driven, but leave a hole
    > open in case there were ever a case the table scheme could not handle?


    I guess that's possible. I thought it was to simplify SimpleTimeZone,
    which "cannot handle historical changes in the offset from GMT and the
    daylight saving schedule," while still supplying historical daylight
    saving time information to TimeZone#getOffset() and
    Calendar#get(Calendar.ZONE_OFFSET), when implemented.

    <http://java.sun.com/javase/6/docs/api/java/util/TimeZone.html>
    <http://java.sun.com/javase/6/docs/api/java/util/Calendar.html>

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Oct 5, 2009
    #9
  10. In comp.lang.java.programmer message <dd0kc5tovakakhorujt5db4l0s9ssia7ov
    @4ax.com>, Mon, 5 Oct 2009 07:25:09, Roedy Green <
    om.invalid> posted:
    >On Sun, 4 Oct 2009 20:17:20 +0100, Dr J R Stockton
    ><> wrote, quoted or indirectly quoted
    >someone who said :
    >
    >>At least one
    >>JavaScript browser makes six changes per year, outside 1970 to 2038.

    >
    >What timezone is that?


    GMT+0, perhaps only GMT+0 - and of course excluding Iceland & Africa.
    See <URL:http://www.merlyn.demon.co.uk/js-datex.htm>, and that page's
    links to forestall other queries.

    One should really test all systems for the middle of every quarter-hour
    within the date range of interest, and a reasonable number of samples
    outside that range; and do so for all distinct locations and with the
    computer "in" both Summer & Winter. With a modern machine, that should
    not take all that long for a single location. I've added it.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, Oct 5, 2009
    #10
  11. John B. Matthews wrote:
    > In article <4ac7cb44$0$290$>,
    > Arne Vajhøj <> wrote:
    >
    >> Roedy Green wrote:
    >>> Is there a simpler way to find out when DST starts in a given year
    >>> than stepping through the year day by day calling
    >>> TimeZone.inDaylightTime( Date )?

    >> No, that information is private in the SimpleTimeZone class.

    >
    > This is correct, but one can examine the values in the private
    > simpleTimeZoneParams array of sun.util.calendar.ZoneInfo. The number and
    > meaning of the parameters are a function of which SimpleTimeZone
    > constructor was used to create the ZoneInfo, as described here:
    >
    > <http://www.docjar.com/html/api/sun/util/calendar/ZoneInfo.java.html>
    >
    > <method>
    > private static void printTzParams (String id) {
    > TimeZone tz = TimeZone.getTimeZone(id);
    > String name = "simpleTimeZoneParams";
    > final Field fields[] = tz.getClass().getDeclaredFields();
    > for (int i = 0; i < fields.length; i++) {
    > if (name.equals(fields.getName())) {
    > try {
    > fields.setAccessible(true);
    > int[] ia = (int[]) fields.get(tz);
    > System.out.print("Params for "
    > + tz.getID() + ": ");
    > for (int j = 0; j < ia.length; j++) {
    > System.out.print(ia[j] + " ");
    > }
    > System.out.println();
    > }
    > catch (IllegalAccessException e) {
    > System.err.println("IllegalAccess: " + name);
    > }
    > }
    > }
    > }
    > </method>
    >
    > <example>
    > Params for Europe/London: 2 -1 1 3600000 2 9 -1 1 3600000 2
    > Params for Europe/Zurich: 2 -1 1 3600000 2 9 -1 1 3600000 2
    > Params for US/Eastern: 2 8 -1 7200000 10 1 -1 7200000
    > Params for US/Pacific: 2 8 -1 7200000 10 1 -1 7200000
    > </example>


    It should also be possible to do the same for SimpleTimeZone,
    but given that a usable workaround exists, then I would avoid
    that type of code.

    Arne
     
    Arne Vajhøj, Oct 6, 2009
    #11
  12. In article <4aca91e5$0$291$>,
    Arne Vajhøj <> wrote:

    > John B. Matthews wrote:
    > > In article <4ac7cb44$0$290$>,
    > > Arne Vajhøj <> wrote:
    > >
    > >> Roedy Green wrote:
    > >>> Is there a simpler way to find out when DST starts in a given
    > >>> year than stepping through the year day by day calling
    > >>> TimeZone.inDaylightTime( Date )?
    > >> No, that information is private in the SimpleTimeZone class.

    > >
    > > This is correct, but one can examine the values in the private
    > > simpleTimeZoneParams array of sun.util.calendar.ZoneInfo. The
    > > number and meaning of the parameters are a function of which
    > > SimpleTimeZone constructor was used to create the ZoneInfo, as
    > > described here:
    > >
    > > <http://www.docjar.com/html/api/sun/util/calendar/ZoneInfo.java.html>


    > [Introspective approach omitted]


    > It should also be possible to do the same for SimpleTimeZone,
    > but given that a usable workaround exists, then I would avoid
    > that type of code.


    On reflection*, you're right. The implementation is private, perhaps
    because it may change. Peeking under the hood is instructive, but
    probably not dependable.

    *In the sense of having thought about it, as well as the technique.

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Oct 6, 2009
    #12
    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. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,301
    Michael Borgwardt
    May 30, 2004
  2. Replies:
    2
    Views:
    1,011
  3. Rakesh
    Replies:
    2
    Views:
    1,981
    Roedy Green
    Apr 3, 2009
  4. david.karr
    Replies:
    34
    Views:
    2,022
    David Karr
    Apr 21, 2009
  5. Replies:
    0
    Views:
    116
Loading...

Share This Page