Skip to content

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

@ivansdworx

Description

@ivansdworx

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions