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]. That would avoid effort spent in truncating post creation of 
Instant
   
   [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:
[email protected]


With regards,
Apache Git Services

Reply via email to