comparison src/org/tmatesoft/hg/core/HgDate.java @ 214:4252faa556cd

Use custom timezone identifier to avoid applying daylight savings from the zone guessed
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 16 May 2011 21:10:36 +0200
parents 644ee58c9f16
children
comparison
equal deleted inserted replaced
211:644ee58c9f16 214:4252faa556cd
40 public HgDate(long millis, int timezone) { 40 public HgDate(long millis, int timezone) {
41 time = millis; 41 time = millis;
42 // @see http://pydoc.org/2.5.1/time.html time.timezone -- difference in seconds between UTC and local standard time 42 // @see http://pydoc.org/2.5.1/time.html time.timezone -- difference in seconds between UTC and local standard time
43 // UTC - local = timezone. local = UTC - timezone 43 // UTC - local = timezone. local = UTC - timezone
44 // In Java, timezone is positive right of Greenwich, UTC+timezone = local 44 // In Java, timezone is positive right of Greenwich, UTC+timezone = local
45 //
46 //
47 /*
48 * The approach with available-short didn't work out as final timezone still relied
49 * on daylight saving settings (and added/substracted hour shift according to date supplied)
50 * E.g. 1218917104000 in zone GMT+2 (hello sample, changeset #2), results in EET timezone and 23 hours instead of 22
51 *
45 String[] available = TimeZone.getAvailableIDs(-timezone * 1000); 52 String[] available = TimeZone.getAvailableIDs(-timezone * 1000);
46 assert available != null && available.length > 0 : String.valueOf(timezone); 53 assert available != null && available.length > 0 : String.valueOf(timezone);
47 // this is sort of hach, I don't know another way how to get 54 // this is sort of hack, I don't know another way how to get
48 // abbreviated name from zone offset (other than to have own mapping) 55 // abbreviated name from zone offset (other than to have own mapping)
49 // And I can't use any id, because e.g. zone with id "US/Mountain" 56 // And I can't use any id, because e.g. zone with id "US/Mountain"
50 // gives incorrect (according to hg cmdline) result, unlike MST or US/Arizona (all ids for zone -0700) 57 // gives incorrect (according to hg cmdline) result, unlike MST or US/Arizona (all ids for zone -0700)
51 // use 1125044450000L to see the difference 58 // use 1125044450000L to see the difference
52 String shortID = TimeZone.getTimeZone(available[0]).getDisplayName(false, TimeZone.SHORT); 59 String shortID = TimeZone.getTimeZone(available[0]).getDisplayName(false, TimeZone.SHORT);
53 // XXX in fact, might need to handle daylight saving time, but not sure how, 60 // XXX in fact, might need to handle daylight saving time, but not sure how,
54 // getTimeZone(GMT-timezone*1000).inDaylightTime()? 61 // getTimeZone(GMT-timezone*1000).inDaylightTime()?
55 TimeZone tz = TimeZone.getTimeZone(shortID); 62 TimeZone tz = TimeZone.getTimeZone(shortID);
63 */
64 int tz_hours = -timezone/3600;
65 int tz_mins = timezone % 3600;
66 String customId = String.format("GMT%+02d:%02d", tz_hours, tz_mins);
67 TimeZone tz = TimeZone.getTimeZone(customId);
56 tzone = tz; 68 tzone = tz;
57 } 69 }
58 70
59 public long getRawTime() { 71 public long getRawTime() {
60 return time; 72 return time;