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

Timezone formatting: shows percentage of minutes in hour instead of minutes #128

Open
ivansdworx opened this issue Dec 14, 2023 · 0 comments

Comments

@ivansdworx
Copy link

ivansdworx commented Dec 14, 2023

Found a bug in date formatting.
Example: Format Date with minutes timezone offset set. Instead of "+5:45" resulted string timezone is "+5:75".
Expected result: "+5:45". As in original Date.

function formatTimeZone(date, info, options) {
const { shortHours, optionalMinutes, separator, localizedName, zZeroOffset } = options;
const offset = date.getTimezoneOffset() / 60;
if (offset === 0 && zZeroOffset) {
return "Z";
}
const sign = offset <= 0 ? "+" : "-";
const hoursMinutes = Math.abs(offset).toString().split(".");
const minutes = hoursMinutes[1] || 0;
let result = sign + (shortHours ? hoursMinutes[0] : pad(hoursMinutes[0], 2));
if (minutes || !optionalMinutes) {
result += (separator ? ":" : EMPTY) + pad(minutes, 2);
}
if (localizedName) {
const localizedFormat = offset === 0 ? info.calendar.gmtZeroFormat : info.calendar.gmtFormat;
result = formatString(localizedFormat, result);
}
return result;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant