From 09d68ae603545ffde2da1d6c96e03c3fa52b5dc1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 10 Mar 2017 17:25:43 +0100 Subject: [PATCH] fixed entity time for timezones with minutes !=0 --- .../siacs/conversations/generator/IqGenerator.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index e4ab2b197..dc292ae07 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -15,6 +15,7 @@ import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.TimeZone; import java.util.UUID; @@ -77,9 +78,16 @@ public class IqGenerator extends AbstractGenerator { time.addChild("utc").setContent(getTimestamp(now)); TimeZone ourTimezone = TimeZone.getDefault(); long offsetSeconds = ourTimezone.getOffset(now) / 1000; - long offsetMinutes = offsetSeconds % (60 * 60); - long offsetHours = offsetSeconds / (60 * 60); - time.addChild("tzo").setContent(String.format("%02d",offsetHours)+":"+String.format("%02d",offsetMinutes)); + long offsetMinutes = Math.abs((offsetSeconds % 3600) / 60); + long offsetHours = offsetSeconds / 3600; + String hours; + if (offsetHours<0) { + hours = String.format(Locale.US,"%03d",offsetHours); + } else { + hours = String.format(Locale.US,"%02d",offsetHours); + } + String minutes = String.format(Locale.US,"%02d",offsetMinutes); + time.addChild("tzo").setContent(hours+":"+minutes); return packet; }