Mercurial > hg4j
changeset 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 | 41a778e3fd31 |
files | src/org/tmatesoft/hg/core/HgDate.java test/org/tmatesoft/hg/test/TestHistory.java |
diffstat | 2 files changed, 44 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgDate.java Fri Apr 29 02:37:52 2011 +0200 +++ b/src/org/tmatesoft/hg/core/HgDate.java Mon May 16 21:10:36 2011 +0200 @@ -42,9 +42,16 @@ // @see http://pydoc.org/2.5.1/time.html time.timezone -- difference in seconds between UTC and local standard time // UTC - local = timezone. local = UTC - timezone // In Java, timezone is positive right of Greenwich, UTC+timezone = local + // + // + /* + * The approach with available-short didn't work out as final timezone still relied + * on daylight saving settings (and added/substracted hour shift according to date supplied) + * E.g. 1218917104000 in zone GMT+2 (hello sample, changeset #2), results in EET timezone and 23 hours instead of 22 + * String[] available = TimeZone.getAvailableIDs(-timezone * 1000); assert available != null && available.length > 0 : String.valueOf(timezone); - // this is sort of hach, I don't know another way how to get + // this is sort of hack, I don't know another way how to get // abbreviated name from zone offset (other than to have own mapping) // And I can't use any id, because e.g. zone with id "US/Mountain" // gives incorrect (according to hg cmdline) result, unlike MST or US/Arizona (all ids for zone -0700) @@ -53,6 +60,11 @@ // XXX in fact, might need to handle daylight saving time, but not sure how, // getTimeZone(GMT-timezone*1000).inDaylightTime()? TimeZone tz = TimeZone.getTimeZone(shortID); + */ + int tz_hours = -timezone/3600; + int tz_mins = timezone % 3600; + String customId = String.format("GMT%+02d:%02d", tz_hours, tz_mins); + TimeZone tz = TimeZone.getTimeZone(customId); tzone = tz; }
--- a/test/org/tmatesoft/hg/test/TestHistory.java Fri Apr 29 02:37:52 2011 +0200 +++ b/test/org/tmatesoft/hg/test/TestHistory.java Mon May 16 21:10:36 2011 +0200 @@ -20,6 +20,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertTrue; +import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -69,11 +70,12 @@ public TestHistory() throws Exception { this(new HgLookup().detectFromWorkingDir()); +// this(new HgLookup().detect("\\temp\\hg\\hello")); } private TestHistory(HgRepository hgRepo) { repo = hgRepo; - eh = new ExecHelper(changelogParser = new LogOutputParser(true), null); + eh = new ExecHelper(changelogParser = new LogOutputParser(true), new File(repo.getLocation())); } @@ -88,39 +90,34 @@ @Test public void testFollowHistory() throws Exception { final Path f = Path.create("cmdline/org/tmatesoft/hg/console/Remote.java"); - try { - if (repo.getFileNode(f).exists()) { // FIXME getFileNode shall not fail with IAE - changelogParser.reset(); - eh.run("hg", "log", "--debug", "--follow", f.toString()); - - class H extends CollectHandler implements FileHistoryHandler { - boolean copyReported = false; - boolean fromMatched = false; - public void copy(FileRevision from, FileRevision to) { - copyReported = true; - fromMatched = "src/com/tmate/hgkit/console/Remote.java".equals(from.getPath().toString()); - } - }; - H h = new H(); - new HgLogCommand(repo).file(f, true).execute(h); - String what = "hg log - FOLLOW FILE HISTORY"; - errorCollector.checkThat(what + "#copyReported ", h.copyReported, is(true)); - errorCollector.checkThat(what + "#copyFromMatched", h.fromMatched, is(true)); - // - // cmdline always gives in changesets in order from newest (bigger rev number) to oldest. - // LogCommand does other way round, from oldest to newest, follewed by revisions of copy source, if any - // (apparently older than oldest of the copy target). Hence need to sort Java results according to rev numbers - final LinkedList<HgChangeset> sorted = new LinkedList<HgChangeset>(h.getChanges()); - Collections.sort(sorted, new Comparator<HgChangeset>() { - public int compare(HgChangeset cs1, HgChangeset cs2) { - return cs1.getRevision() < cs2.getRevision() ? 1 : -1; - } - }); - report(what, sorted, false); + assertTrue(repo.getFileNode(f).exists()); + changelogParser.reset(); + eh.run("hg", "log", "--debug", "--follow", f.toString()); + + class H extends CollectHandler implements FileHistoryHandler { + boolean copyReported = false; + boolean fromMatched = false; + public void copy(FileRevision from, FileRevision to) { + copyReported = true; + fromMatched = "src/com/tmate/hgkit/console/Remote.java".equals(from.getPath().toString()); } - } catch (IllegalArgumentException ex) { - System.out.println("Can't test file history with follow because need to query specific file with history"); - } + }; + H h = new H(); + new HgLogCommand(repo).file(f, true).execute(h); + String what = "hg log - FOLLOW FILE HISTORY"; + errorCollector.checkThat(what + "#copyReported ", h.copyReported, is(true)); + errorCollector.checkThat(what + "#copyFromMatched", h.fromMatched, is(true)); + // + // cmdline always gives in changesets in order from newest (bigger rev number) to oldest. + // LogCommand does other way round, from oldest to newest, follewed by revisions of copy source, if any + // (apparently older than oldest of the copy target). Hence need to sort Java results according to rev numbers + final LinkedList<HgChangeset> sorted = new LinkedList<HgChangeset>(h.getChanges()); + Collections.sort(sorted, new Comparator<HgChangeset>() { + public int compare(HgChangeset cs1, HgChangeset cs2) { + return cs1.getRevision() < cs2.getRevision() ? 1 : -1; + } + }); + report(what, sorted, false); } private void report(String what, List<HgChangeset> r, boolean reverseConsoleResult) { @@ -142,7 +139,7 @@ } Record cr = consoleResultItr.next(); int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; - x |= cs.getDate().equals(cr.date) ? 0x2 : 0; + x |= cs.getDate().toString().equals(cr.date) ? 0x2 : 0; x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; x |= cs.getUser().equals(cr.user) ? 0x8 : 0; // need to do trim() on comment because command-line template does, and there are