You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by "phet (via GitHub)" <gi...@apache.org> on 2023/08/19 02:12:03 UTC

[GitHub] [gobblin] phet commented on a diff in pull request #3747: [GOBBLIN-1885] Ensure All Logged Timestamps are in UTC

phet commented on code in PR #3747:
URL: https://github.com/apache/gobblin/pull/3747#discussion_r1299007078


##########
gobblin-service/src/main/java/org/apache/gobblin/service/modules/scheduler/GobblinServiceJobScheduler.java:
##########
@@ -467,6 +467,18 @@ protected static String jobSchedulerTracePrefixBuilder(Properties jobProps) {
         jobProps.getProperty(ConfigurationKeys.FLOW_GROUP_KEY, "<<no flow group>>"));
   }
 
+  /**
+   * Takes a given Date object and converts the timezone to UTC before returning the number of millseconds since epoch
+   * @param date
+   */
+  public static long getMillisecondsSinceEpochInUTC(Date date) {
+    // Create a Calendar object and set it to the given Date
+    Calendar calendar = Calendar.getInstance();
+    calendar.setTime(date);
+    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
+    return calendar.getTimeInMillis();
+  }

Review Comment:
   let's opt for the modern, Joda/`java.time` classes.  I believe something like:
   ```
   ZonedDateTime.of(
       LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()), 
       ZoneOffset.UTC
   ).toInstant().toEpochMilli()
   ```
   
   nit: this is not a accessor (`get`), but a conversion, so `asUTCEpochMillis`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org