Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rharshit82 committed Aug 13, 2023
1 parent 0673fc6 commit 1d7a006
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1d7a006

Please sign in to comment.