This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e9d579479 fix for the test failing in different timezone
     new 6654b3132c Merge pull request #1386 from 
zan-mateusz/fix/timetest-failing-in-different-timezone
6e9d579479 is described below

commit 6e9d57947912263bd1089f18c5c98d046e6dee6b
Author: zan-mateusz <[email protected]>
AuthorDate: Mon Apr 3 14:53:29 2023 +0200

    fix for the test failing in different timezone
---
 .../src/main/java/org/apache/brooklyn/util/time/Time.java    | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java 
b/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java
index 4e1d904f0b..975b1453a7 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java
@@ -153,7 +153,7 @@ public class Time {
 
     /** as {@link #makeDateStampString()}, with millis and possibly seconds 
removed if 0, with 'Z' at the end to indicate UTC */
     public static String makeDateStampStringZ(Instant instant) {
-        String s = makeDateStampString(instant.toEpochMilli());
+        String s = makeDateStampStringZ(instant.toEpochMilli());
         if (s.endsWith("000")) {
             s = Strings.removeFromEnd(s, "000");
             s = Strings.removeFromEnd(s, "00");
@@ -163,7 +163,7 @@ public class Time {
 
     /** as {@link #makeDateStampString()}, with millis and possibly seconds 
removed if 0, with 'Z' at the end to indicate UTC */
     public static String makeDateStampStringZ(Date date) {
-        String s = makeDateStampString(date.getTime());
+        String s = makeDateStampStringZ(date.getTime());
         if (s.endsWith("000")) {
             s = Strings.removeFromEnd(s, "000");
             s = Strings.removeFromEnd(s, "00");
@@ -206,6 +206,14 @@ public class Time {
         return new SimpleDateFormat(DATE_FORMAT_STAMP).format(new Date(date));
     }
 
+    /** returns the time in {@value #DATE_FORMAT_STAMP} format, given a long 
(e.g. returned by System.currentTimeMillis), in UTC timezone;
+     * cf {@link #makeDateStampStringZ()} */
+    public static String makeDateStampStringZ(long date) {
+        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_STAMP);
+        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+        return dateFormat.format(new Date(date));
+    }
+
     /** returns the current time in {@value #DATE_FORMAT_SIMPLE_STAMP} format, 
      * suitable for machines to read but easier for humans too, 
      * like {@link #makeDateStampString()} but not as precise */

Reply via email to