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);
// 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();
/**
* 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
*/
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();