From: Janus Varmarken Date: Thu, 26 Jul 2018 23:00:50 +0000 (-0700) Subject: Upate date format to match format used in timestamp files produced by experiment... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=pingpong.git;a=commitdiff_plain;h=eaa2a0871c8ed74e6aea550b41521e5a9f112ec8 Upate date format to match format used in timestamp files produced by experiment script --- diff --git a/Code/Projects/DateWriter/DateWriter.java b/Code/Projects/DateWriter/DateWriter.java index adde143..d965bbb 100644 --- a/Code/Projects/DateWriter/DateWriter.java +++ b/Code/Projects/DateWriter/DateWriter.java @@ -11,13 +11,14 @@ public class DateWriter { public static void main(String[] args) throws IOException { if (args.length < 3) { - System.out.println("Usage: java /path/to/file/with/timestamps /path/to/new/timestamp/file/with/dates initial_date_in_uuuu-MM-dd_format"); + System.out.println("Usage: java " + DateWriter.class.getSimpleName() + " /path/to/file/with/timestamps /path/to/new/timestamp/file/with/dates initial_date_in_MM/dd/uuuu_format"); System.exit(1); } String pathOriginal = args[0]; String pathModified = args[1]; String initialDateStr = args[2]; - LocalDate date = LocalDate.parse(initialDateStr, DateTimeFormatter.ofPattern("uuuu-MM-dd")); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("MM/dd/uuuu"); + LocalDate date = LocalDate.parse(initialDateStr, dateFormatter); File originalFile = new File(pathOriginal); // Create output file File modifiedFile = new File(pathModified); @@ -31,7 +32,7 @@ public class DateWriter { // Advance date date = date.plusDays(1); } - writer.println(String.format("%s %s", date.toString(), line)); + writer.println(String.format("%s %s", date.format(dateFormatter), line)); prevLine = line; } writer.flush(); diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/TriggerTimesFileReader.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/TriggerTimesFileReader.java index 592bcd7..b116909 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/TriggerTimesFileReader.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/TriggerTimesFileReader.java @@ -48,7 +48,7 @@ public class TriggerTimesFileReader { /** * Parses a timestamp string to an {@link Instant} (UTC). Assumes timestamps are LA time. - * Format is expected to be either "uuuu-MM-dd HH:mm:ss" or "uuuu-MM-dd h:mm:ss a". + * Format is expected to be either "MM/dd/uuuu HH:mm:ss" or "MM/dd/uuuu h:mm:ss a". * * @param timestampStr The string containing a date-time timestamp for LA's timezone. * @param _24hFormat {@code true} if the time in {@code timestampStr} is given in 24 hour format, {@code false} if @@ -59,7 +59,7 @@ public class TriggerTimesFileReader { */ public Instant parseTriggerTimestamp(String timestampStr, boolean _24hFormat) { // Note: only one 'h' when not prefixed with leading 0 for 1-9; and only one 'a' for AM/PM marker in Java 8 time - String format = _24hFormat ? "uuuu-MM-dd HH:mm:ss" : "uuuu-MM-dd h:mm:ss a"; + String format = _24hFormat ? "MM/dd/uuuu HH:mm:ss" : "MM/dd/uuuu h:mm:ss a"; LocalDateTime localDateTime = LocalDateTime.parse(timestampStr, DateTimeFormatter.ofPattern(format, Locale.US)); ZonedDateTime laZonedDateTime = localDateTime.atZone(ZONE_ID_LOS_ANGELES); return laZonedDateTime.toInstant();