// https://gist.github.com/pjdietz/e0545332e2fc67a9a460 const pad = (n: number): string => String(n).padStart(2, '0') const timezoneOffset = (offset: number): string => { if (offset === 0) { return 'Z' } const sign = offset > 0 ? '-' : '+' const absOffset = Math.abs(offset) return `${sign}${pad(Math.floor(absOffset / 60))}:${pad(absOffset % 60)}` } /** * Format a local date as an RFC 3339 date with timezone * @param d */ const rfc3339 = () => { const date = new Date() return ( date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + 'T' + pad(date.getHours()) + ':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds()) + timezoneOffset(date.getTimezoneOffset()) ) } export default rfc3339