cjj2010 commented on code in PR #4712:
URL: https://github.com/apache/calcite/pull/4712#discussion_r2652378573


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -7491,4 +7493,91 @@ private enum PartToExtract {
     AUTHORITY,
     USERINFO;
   }
+
+  /** SQL {@code AGE(timestamp1, timestamp2)} function. */
+  private static String age(long timestamp1, long timestamp2) {

Review Comment:
   > ZonedDateTime zdt1 = Instant.ofEpochMilli(timestamp1)
   >         .atZone(ZoneOffset.UTC);
   >     ZonedDateTime zdt2 = Instant.ofEpochMilli(timestamp2)
   >         .atZone(ZoneOffset.UTC);
   > 
   >     Period period = Period.between(zdt2.toLocalDate(), zdt1.toLocalDate());
   >     Duration duration = Duration.between(zdt2, zdt1);
   > 
   >     int years = period.getYears();
   >     int months = period.getMonths();
   >     int days = period.getDays();
   > 
   >     long totalSeconds = duration.getSeconds();
   >     long hours = (totalSeconds / 3600) % 24;
   >     long minutes = (totalSeconds / 60) % 60;
   >     long seconds = totalSeconds % 60;
   >     long millis = duration.toMillis() % 1000;
   
   Thank you very much for your suggestion. The above code is being executed
   SELECT AGE(timestamp '2023-12-25 00:00:00', timestamp '2020-01-01 23:59:59') 
FROM (VALUES (1)) t, Returned 3 years 11 mons 24 days 0 hours 0 mins 1.0 secs, 
but pgSQL returned
   3 years 11 mons 23 days 0 hours 0 mins 1.0 secs, This test case did not 
pass, and one more thing is that String.form seems to be prohibited from use. 
The code I submitted for the first time did not pass the detection because of 
its use



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to