betterDateProps = new Map(Object.entries({
value: ["getTime", "setTime"],
epoch: [
function getEpoch() { return this.value / 1000; },
function setEpoch(v) { return this.value = v * 1000; },
{
remarks: `This is equivalent to the date’s internal value but expressed in seconds, including the fractional component.`,
format: {
class: "Intl.NumberFormat",
notation: "standard",
style: "decimal",
minimumFractionDigits: 3
}
}
],
date: [
function getDate() { return new Date(this.year, this.month, this.day); },
undefined,
{
remarks: `This returns a new <code class="observablehq--key">Date</code> object representing the same date but at midnight. This is simply copying the year, month, and day to a new <code class="observablehq--key">Date</code> object.`
}
],
dateUTC: [
function getDateUTC() {
let d = new Date(this.year, this.month, this.day);
debugger;
d.epoch -= this.timezoneOffset * 60;
return d;
},
undefined,
{
remarks: `This returns a new <code class="observablehq--key">Date</code> object representing the same date but at midnight in UTC. This is simply copying the year, month, and day to a new <code class="observablehq--key">Date</code> object.`
}
],
time: [
function getTime() {
let d = this.date;
d.value = this.value - d.value;
return d;
},
undefined,
{
remarks: `This returns a new <code class="observablehq--key">Date</code> object representing just the time component of the <code class="observablehq--key">Date</code> object. The date component will be that of the Unix epoch.`,
format: {
class: "Intl.DateTimeFormat",
hourCycle: "h24",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
fractionalSecondDigits: 3,
timeZoneName: "shortOffset"
}
}
],
timeUTC: [
function getTimeUTC() {
let d = this.dateUTC;
d.value = this.value - d.value;
return d;
},
undefined,
{
remarks: `This returns a new <code class="observablehq--key">Date</code> object representing just the time component of the <code class="observablehq--key">Date</code> object in UTC. The date component will be that of the Unix epoch.`,
format: {
class: "Intl.DateTimeFormat",
hourCycle: "h24",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
fractionalSecondDigits: 3,
timeZoneName: "shortOffset"
}
}
],
year: ["getFullYear", "setFullYear"],
month: ["getMonth", "setMonth"],
day: ["getDate", "setDate"],
weekday: "getDay",
hour: ["getHours", "setHours"],
minute: ["getMinutes", "setMinutes"],
second: ["getSeconds", "setSeconds"],
millisecond: ["getMilliseconds", "setMilliseconds"],
sec: [
function getSec() { return this.second + this.millisecond / 1000; },
function setSec(v) {
return this.value = this.value - 1000 * this.second - this.millisecond + 1000 * v;
},
{
remarks: `This is the combination of <a href="#prop-second"><code class="observablehq--key">second</code></a> and <a href="#prop-millisecond"><code class="observablehq--key">millisecond</code></a>, expressed as seconds.`,
format: {
class: "Intl.NumberFormat",
notation: "standard",
style: "decimal",
minimumFractionDigits: 3
}
}
],
yearUTC: ["getUTCFullYear", "setUTCFullYear"],
monthUTC: ["getUTCMonth", "setUTCMonth"],
dayUTC: ["getUTCDate", "setUTCDate"],
weekdayUTC: "getUTCDay",
hourUTC: ["getUTCHours", "setUTCHours"],
minuteUTC: ["getUTCMinutes", "setUTCMinutes"],
secondUTC: ["getUTCSeconds", "setUTCSeconds"],
millisecondUTC: ["getUTCMilliseconds", "setUTCMilliseconds"],
secUTC: [
function getUTCSec() { return this.secondUTC + this.millisecondUTC / 1000; },
function setUTCSec(v) {
return this.value = this.value - 1000 * this.secondUTC - this.millisecondUTC + 1000 * v;
},
{
remarks: `This is the combination of <a href="#prop-secondUTC"><code class="observablehq--key">secondUTC</code></a> and <a href="#prop-millisecondUTC"><code class="observablehq--key">millisecondUTC</code></a>, expressed as seconds.`,
format: {
class: "Intl.NumberFormat",
notation: "standard",
style: "decimal",
minimumFractionDigits: 3
}
}
],
timezoneOffset: "getTimezoneOffset",
dateString: "toDateString",
timeString: "toTimeString",
ISOString: "toISOString",
UTCString: "toUTCString"
}).map(([key, value]) => [key, Object.defineProperty(resolveDescriptor(value), Symbol.toStringTag, {value: key})]))