Upate date format to match format used in timestamp files produced by experiment...
authorJanus Varmarken <varmarken@gmail.com>
Thu, 26 Jul 2018 23:00:50 +0000 (16:00 -0700)
committerJanus Varmarken <varmarken@gmail.com>
Thu, 26 Jul 2018 23:00:50 +0000 (16:00 -0700)
Code/Projects/DateWriter/DateWriter.java
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/TriggerTimesFileReader.java

index adde143..d965bbb 100644 (file)
@@ -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();
index 592bcd7..b116909 100644 (file)
@@ -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();