Hi,

I have modelled calendar entries, which have a timestamp attribute. I wanted to build a qualifier that matches all entries within a month so I created start and end timestamps programatically. The start timestamp is no problem. To get the end timestamp, I used NSTimestamp.timestampByAddingGregorianUnits and added "a month minus one second". This works fine for GMT, but gives me funky results for e.g. Europe/Berlin. Please see code and output below. Any ideas? This is with WO 5.3.3.

Timo



public class NSTimestampTest {
        public static void main(String[] args) {
                int year = 2008;

                // This one works
                NSTimeZone gmt = NSTimeZone.getGMT();
                test(gmt, year);

                // This one doesn't
NSTimeZone berlin = NSTimeZone.timeZoneWithName("Europe/Berlin", false);
                test(berlin, year);
        }

        private static void test(NSTimeZone timezone, int year) {
NSTimestampFormatter formatter = new NSTimestampFormatter("%Y-%m-%d %H:%M:%S %Z");
                formatter.setDefaultFormatTimeZone(timezone);
                
                for (int month = 1; month <= 12; month++) {
NSTimestamp start = new NSTimestamp(year, month, 1, 0, 0, 0, timezone); NSTimestamp end = start.timestampByAddingGregorianUnits(0, 1, 0, 0, 0, -1); System.out.printf("%s -> %s\n", formatter.format(start), formatter.format(end));
                }
        }
}

results in

2008-01-01 00:00:00 Etc/GMT -> 2008-01-31 23:59:59 Etc/GMT
2008-02-01 00:00:00 Etc/GMT -> 2008-02-29 23:59:59 Etc/GMT
2008-03-01 00:00:00 Etc/GMT -> 2008-03-31 23:59:59 Etc/GMT
2008-04-01 00:00:00 Etc/GMT -> 2008-04-30 23:59:59 Etc/GMT
2008-05-01 00:00:00 Etc/GMT -> 2008-05-31 23:59:59 Etc/GMT
2008-06-01 00:00:00 Etc/GMT -> 2008-06-30 23:59:59 Etc/GMT
2008-07-01 00:00:00 Etc/GMT -> 2008-07-31 23:59:59 Etc/GMT
2008-08-01 00:00:00 Etc/GMT -> 2008-08-31 23:59:59 Etc/GMT
2008-09-01 00:00:00 Etc/GMT -> 2008-09-30 23:59:59 Etc/GMT
2008-10-01 00:00:00 Etc/GMT -> 2008-10-31 23:59:59 Etc/GMT
2008-11-01 00:00:00 Etc/GMT -> 2008-11-30 23:59:59 Etc/GMT
2008-12-01 00:00:00 Etc/GMT -> 2008-12-31 23:59:59 Etc/GMT
2008-01-01 00:00:00 Europe/Berlin -> 2008-01-31 23:59:59 Europe/Berlin
2008-02-01 00:00:00 Europe/Berlin -> 2008-02-29 23:59:59 Europe/Berlin
2008-03-01 00:00:00 Europe/Berlin -> 2008-03-29 23:59:59 Europe/Berlin
2008-04-01 00:00:00 Europe/Berlin -> 2008-04-30 23:59:59 Europe/Berlin
2008-05-01 00:00:00 Europe/Berlin -> 2008-05-30 23:59:59 Europe/Berlin
2008-06-01 00:00:00 Europe/Berlin -> 2008-06-30 23:59:59 Europe/Berlin
2008-07-01 00:00:00 Europe/Berlin -> 2008-07-30 23:59:59 Europe/Berlin
2008-08-01 00:00:00 Europe/Berlin -> 2008-08-31 23:59:59 Europe/Berlin
2008-09-01 00:00:00 Europe/Berlin -> 2008-09-30 23:59:59 Europe/Berlin
2008-10-01 00:00:00 Europe/Berlin -> 2008-10-30 22:59:59 Europe/Berlin
2008-11-01 00:00:00 Europe/Berlin -> 2008-11-30 23:59:59 Europe/Berlin
2008-12-01 00:00:00 Europe/Berlin -> 2008-12-30 23:59:59 Europe/Berlin



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to