From 1d7a0062d5599555431cf6649a33e80355876629 Mon Sep 17 00:00:00 2001 From: Harshit Raj <35199148+rharshit82@users.noreply.github.com> Date: Sun, 13 Aug 2023 17:40:33 +0530 Subject: [PATCH] bug fixes --- lib/time.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/time.js b/lib/time.js index 0a62a8d0..ca3654cb 100644 --- a/lib/time.js +++ b/lib/time.js @@ -152,19 +152,27 @@ function CronTime(luxon) { } if (typeof this.utcOffset !== 'undefined') { - let offset = - this.utcOffset >= 60 || this.utcOffset <= -60 - ? this.utcOffset / 60 - : this.utcOffset; + if (typeof this.utcOffset === 'string') { + const parts = this.utcOffset.split(':'); + const hours = parseInt(parts[0]); + const minutes = parseInt(parts[1]); + if (this.utcOffset[0] === '-') this.utcOffset = hours * 60 - minutes; + else this.utcOffset = hours * 60 + minutes; + } + let offset = this.utcOffset / 60; + offset = parseInt(offset); const remainderMins = Math.abs(this.utcOffset - offset * 60); + const remainderMinsString = + remainderMins >= 10 ? remainderMins : '0' + remainderMins; let utcZone = 'UTC'; - if (offset < 0 || remainderMins > 0) { - utcZone += `${offset}:${remainderMins}`; - } else if (offset > 0 || remainderMins > 0) { - utcZone += `+${offset}:${remainderMins}`; + + if (this.utcOffset < 0) { + utcZone += `${offset === 0 ? '-0' : offset}:${remainderMinsString}`; + } else { + utcZone += `+${offset}:${remainderMinsString}`; } date = date.setZone(utcZone);