Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for fractional offset (minutes support) #655

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,18 @@ function CronTime(luxon) {
this.utcOffset >= 60 || this.utcOffset <= -60
? this.utcOffset / 60
: this.utcOffset;

// remainder of division by 60
let remainder = offset - Math.floor(offset);
const remainderMins = remainder * 60;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than use a decimal fraction and multiply it by 60, since we already have access to the minutes with this.utcOffset, could you use that to calculate the remaining minutes? like remainderMins = this.utcOffset - (offset * 60)? just to minimize the risk of JS weirdness with decimal fractions

while you're there feel free to use Math.floor(offset) instead of parseInt(offset) and move it above the code you're adding


offset = parseInt(offset);

let utcZone = 'UTC';
if (offset < 0) {
utcZone += offset;
} else if (offset > 0) {
utcZone += `+${offset}`;
} else if (offset > 0 || remainderMins > 0) {
utcZone += `+${offset}:${remainderMins}`;
}

date = date.setZone(utcZone);
Expand Down