@stacksjs/datetime 0.74.62 → 0.74.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -12,3 +12,5 @@ export { parse } from './parse';
12
12
  * ```
13
13
  */
14
14
  export { format as dateFormat } from './format';
15
+ // Wall-clock time in a named zone <-> the real instant (event feeds, schema.org).
16
+ export { isoInZone, zonedTimeToUtc, zoneOffsetMinutes } from './zone';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{DateTime,now}from"./now";export{format}from"./format";export{parse}from"./parse";export{format as dateFormat}from"./format";
1
+ export{DateTime,now}from"./now";export{format}from"./format";export{parse}from"./parse";export{format as dateFormat}from"./format";export{isoInZone,zonedTimeToUtc,zoneOffsetMinutes}from"./zone";
package/dist/zone.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /** Offset of `timeZone` from UTC at `instant`, in minutes (New York in July: -240). */
2
+ export declare function zoneOffsetMinutes(instant: Date, timeZone: string): number;
3
+ /**
4
+ * The instant at which clocks in `timeZone` read `wallClock`.
5
+ *
6
+ * `wallClock` is `YYYY-MM-DD`, `YYYY-MM-DDTHH:mm` or `YYYY-MM-DDTHH:mm:ss`,
7
+ * with no offset. A string that carries its own offset is already an instant,
8
+ * so it is rejected rather than silently reinterpreted.
9
+ *
10
+ * A time that does not exist (skipped by a spring-forward) resolves to the
11
+ * instant just after the gap; a time that happens twice (the fall-back hour)
12
+ * resolves to the first of them, which is what a box office means by it.
13
+ *
14
+ * @example
15
+ * zonedTimeToUtc('2026-10-01T20:00:00', 'America/New_York').toISOString()
16
+ * // '2026-10-02T00:00:00.000Z'
17
+ */
18
+ export declare function zonedTimeToUtc(wallClock: string, timeZone: string): Date;
19
+ /**
20
+ * ISO 8601 with the zone's offset rather than `Z`: `2026-10-01T20:00:00-04:00`.
21
+ *
22
+ * This is the form schema.org Event `startDate` wants. A bare local time is
23
+ * ambiguous and a `Z` time shows the wrong hour to anyone who reads it.
24
+ */
25
+ export declare function isoInZone(instant: Date, timeZone: string): string;
package/dist/zone.js ADDED
@@ -0,0 +1 @@
1
+ const WALL_CLOCK=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/;export function zoneOffsetMinutes(instant,timeZone){const parts=new Intl.DateTimeFormat("en-US",{timeZone,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(instant),get=(type)=>Number(parts.find((p)=>p.type===type)?.value??0),asUtc=Date.UTC(get("year"),get("month")-1,get("day"),get("hour"),get("minute"),get("second")),whole=Math.floor(instant.getTime()/1000)*1000;return Math.round((asUtc-whole)/60000)}export function zonedTimeToUtc(wallClock,timeZone){const match=WALL_CLOCK.exec(wallClock.trim());if(!match)throw TypeError(`zonedTimeToUtc expects a wall-clock time like 2026-10-01T20:00:00, got "${wallClock}"`);const[,y,mo,d,h="0",mi="0",s="0"]=match,guess=Date.UTC(Number(y),Number(mo)-1,Number(d),Number(h),Number(mi),Number(s)),first=guess-zoneOffsetMinutes(new Date(guess),timeZone)*60000,second=guess-zoneOffsetMinutes(new Date(first),timeZone)*60000;if(second===first)return new Date(second);const[early,late]=first<second?[first,second]:[second,first];if(early+zoneOffsetMinutes(new Date(early),timeZone)*60000===guess)return new Date(early);return new Date(late)}export function isoInZone(instant,timeZone){const offset=zoneOffsetMinutes(instant,timeZone),local=new Date(Math.floor(instant.getTime()/1000)*1000+offset*60000),sign=offset<0?"-":"+",abs=Math.abs(offset),pad=(n)=>String(n).padStart(2,"0");return`${local.toISOString().slice(0,19)}${sign}${pad(Math.floor(abs/60))}:${pad(abs%60)}`}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/datetime",
3
3
  "type": "module",
4
- "version": "0.74.62",
4
+ "version": "0.74.64",
5
5
  "description": "The Stacks datetime helpers.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "better-dx": "^0.2.24",
62
- "@stacksjs/utils": "0.74.62"
62
+ "@stacksjs/utils": "0.74.64"
63
63
  },
64
64
  "sideEffects": false
65
65
  }