Skip to content

Commit

Permalink
Ensuring all times are in UTC, including D3's scales, as a fix for is…
Browse files Browse the repository at this point in the history
…sue #240
  • Loading branch information
grahamwills committed Jun 30, 2017
1 parent b8fed6f commit 8ec34b1
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 4 deletions.
Binary file modified R/inst/java/brunel-core-2.4.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion core/src/main/java/org/brunel/build/ScaleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public int defineScaleWithDomain(String name, Field[] fields, ScalePurpose purpo
v = partitionPoints[i];
divs[i] = dateBuilder.make(Data.asDate(v), dateFormat, true);
}
out.add("d3.scaleTime()");
out.add("d3.scaleUtc()");
} else {
// If requested to have a specific transform, util that. Otherwise util the one the field suggests.
// Some scales (like for an area size) have a default transform (e.g. root) and we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public DataTableWriter(VisItem main, Set<ElementStructure> elements, ScriptWrite
this.options = options;
dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
dateTimeFormatter = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss");
dateTimeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
dateTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/brunel/build/util/BuildUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String make(Date d, DateFormat dateFormat, boolean wrappedWithMake) {
text = String.format("'%d-%02d-%02d'",
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
} else {
text = String.format("'%d-%02d-%02dT%02d:%02d:%02d'",
text = String.format("'%d-%02d-%02dT%02d:%02d:%02dZ'",
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH),
calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND)
);
Expand Down
3 changes: 2 additions & 1 deletion data/src/test/java/org/brunel/data/TestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public void testDates() {
assertEquals(0.25, Data.asNumeric(Data.asDate("January 1, 1970 6:00:00")), 0.001);
assertEquals(0.125, Data.asNumeric(Data.asDate("January 1, 1970 3:00:00")), 0.001);
assertEquals(1.0 / 3600 / 24, Data.asNumeric(Data.asDate("1970-01-01T00:00:01")), 0.000001);
assertEquals(1.0 / 3600 / 24, Data.asNumeric(Data.asDate("00:00:01")), 0.000001);
assertEquals(1.0 / 3600 / 24, Data.asNumeric(Data.asDate("00:00:01")), 0.000001);
assertEquals((11*60+50) / 60.0 / 24, Data.asNumeric(Data.asDate("11:50")), 0.000001);
assertEquals((7 + 45 / 60.0 + 22 / 3600.0) / 24.0, Data.asNumeric(Data.asDate("07:45:22")), 0.000001);
assertEquals((10 + 45 / 60.0 + 22 / 3600.0) / 24.0, Data.asNumeric(Data.asDate("10:45:22")), 0.000001);
assertEquals(null, Data.asDate(null));
Expand Down
Binary file modified python/brunel/lib/brunel-core-2.4.jar
Binary file not shown.

0 comments on commit 8ec34b1

Please sign in to comment.