You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2019/05/30 05:55:38 UTC

[GitHub] [incubator-openwhisk] chetanmeh commented on a change in pull request #4497: Use Instant with milli second precision

chetanmeh commented on a change in pull request #4497: Use Instant with milli second precision
URL: https://github.com/apache/incubator-openwhisk/pull/4497#discussion_r288866684
 
 

 ##########
 File path: common/scala/src/main/scala/org/apache/openwhisk/common/WhiskInstants.scala
 ##########
 @@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.openwhisk.common
+
+import java.time.Instant
+import java.time.temporal.ChronoUnit
+
+/**
+ * JDK 11 Instant uses nano second precision by default. However OpenWhisk usage of Instant in
+ * many cases involves storing the timestamp in database which uses milli second precision.
+ *
+ * To ensure consistency below utilities can be used to truncate the Instant to millis
+ */
+trait WhiskInstants {
+
+  implicit class InstantImplicits(i: Instant) {
+    def inMills = i.truncatedTo(ChronoUnit.MILLIS)
 
 Review comment:
   @jvz Used the approach suggested by you to truncate the `Instant`. Though we can possibly optimize it by having a custom `Clock` which uses [jdk 8 approach][1]
   
   [1]: https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/classes/java/time/Clock.java#L470

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services