@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
26 lines (22 loc) • 689 B
JavaScript
/*!
* @techmely/utils
* Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
* MIT Licensed
*/
// src/toISOStringTimezone/index.ts
var pad = (n) => `${Math.floor(Math.abs(n))}`.padStart(2, "0");
var getTimezoneOffset = (date) => {
const tzOffset = -date.getTimezoneOffset();
const diff = tzOffset >= 0 ? "+" : "-";
return `${diff + pad(tzOffset / 60)}:${pad(tzOffset % 60)}`;
};
function toISOStringTimezone(date) {
return `${date.getFullYear()}
-${pad(date.getMonth() + 1)}
-${pad(date.getDate())}
T${pad(date.getHours())}
:${pad(date.getMinutes())}
:${pad(date.getSeconds())}
${getTimezoneOffset(date)}`;
}
export { toISOStringTimezone };