From 6a834695ebb42f478ee1ba6f87201e6c24ad5405 Mon Sep 17 00:00:00 2001
From: iamkun <kunhello@outlook.com>
Date: Thu, 6 Aug 2020 11:51:46 +0800
Subject: [PATCH] fix: fix Timezone plugin UTCOffset rounding bug

fix #986
---
 src/plugin/timezone/index.js | 2 +-
 test/plugin/timezone.test.js | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/plugin/timezone/index.js b/src/plugin/timezone/index.js
index 7cf7c34be..4e494d31c 100644
--- a/src/plugin/timezone/index.js
+++ b/src/plugin/timezone/index.js
@@ -54,7 +54,7 @@ export default (o, c, d) => {
   const proto = c.prototype
   proto.tz = function (timezone) {
     const target = this.toDate().toLocaleString('en-US', { timeZone: timezone })
-    const diff = (this.toDate() - new Date(target)) / 1000 / 60
+    const diff = Math.round((this.toDate() - new Date(target)) / 1000 / 60)
     return d(target).utcOffset(localUtcOffset - diff, true)
   }
   d.tz = function (input, timezone) {
diff --git a/test/plugin/timezone.test.js b/test/plugin/timezone.test.js
index 3411bb7f4..a8c02ed32 100644
--- a/test/plugin/timezone.test.js
+++ b/test/plugin/timezone.test.js
@@ -77,6 +77,13 @@ describe('Convert', () => {
       expect(dec.tz('Australia/Sydney').format('ha')).toBe('11pm')
     })
   })
+
+  it('format Z', () => {
+    [dayjs, moment].forEach((_) => {
+      const losAngeles = _('2020-08-06T03:48:10.258Z').tz('Asia/Tokyo')
+      expect(losAngeles.format('Z')).toBe('+09:00')
+    })
+  })
 })