@zag-js/date-utils 0.0.0-dev-20230321203218 → 0.0.0-dev-20230326221705

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.
@@ -0,0 +1,9 @@
1
+ // src/format-date.ts
2
+ function formatDate(date, formatString, locale, timeZone = "UTC") {
3
+ const nativeDate = date.toDate(timeZone);
4
+ return formatString.replace(/yyyy/gi, nativeDate.toLocaleString(locale, { year: "numeric", timeZone })).replace(/yy/gi, nativeDate.toLocaleString(locale, { year: "2-digit", timeZone })).replace(/dd/gi, nativeDate.toLocaleString(locale, { day: "2-digit", timeZone })).replace(/d/gi, nativeDate.toLocaleString(locale, { day: "numeric", timeZone })).replace(/mmmm/gi, nativeDate.toLocaleString(locale, { month: "long", timeZone })).replace(/mmm/gi, nativeDate.toLocaleString(locale, { month: "short", timeZone })).replace(/mm/gi, nativeDate.toLocaleString(locale, { month: "2-digit", timeZone })).replace(/m/gi, nativeDate.toLocaleString(locale, { month: "numeric", timeZone }));
5
+ }
6
+
7
+ export {
8
+ formatDate
9
+ };
@@ -0,0 +1,5 @@
1
+ import { CalendarDate } from '@internationalized/date';
2
+
3
+ declare function formatDate(date: CalendarDate, formatString: string, locale: string, timeZone?: string): string;
4
+
5
+ export { formatDate };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/format-date.ts
21
+ var format_date_exports = {};
22
+ __export(format_date_exports, {
23
+ formatDate: () => formatDate
24
+ });
25
+ module.exports = __toCommonJS(format_date_exports);
26
+ function formatDate(date, formatString, locale, timeZone = "UTC") {
27
+ const nativeDate = date.toDate(timeZone);
28
+ return formatString.replace(/yyyy/gi, nativeDate.toLocaleString(locale, { year: "numeric", timeZone })).replace(/yy/gi, nativeDate.toLocaleString(locale, { year: "2-digit", timeZone })).replace(/dd/gi, nativeDate.toLocaleString(locale, { day: "2-digit", timeZone })).replace(/d/gi, nativeDate.toLocaleString(locale, { day: "numeric", timeZone })).replace(/mmmm/gi, nativeDate.toLocaleString(locale, { month: "long", timeZone })).replace(/mmm/gi, nativeDate.toLocaleString(locale, { month: "short", timeZone })).replace(/mm/gi, nativeDate.toLocaleString(locale, { month: "2-digit", timeZone })).replace(/m/gi, nativeDate.toLocaleString(locale, { month: "numeric", timeZone }));
29
+ }
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ formatDate
33
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ formatDate
3
+ } from "./chunk-J22B5EMX.mjs";
4
+ export {
5
+ formatDate
6
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  formatSelectedDate
3
- } from "./chunk-LQAXQPWP.mjs";
4
- import "./chunk-HKHGJ6WS.mjs";
3
+ } from "./chunk-LOHO72U6.mjs";
5
4
  import "./chunk-ODG5YF5H.mjs";
6
5
  import "./chunk-KN3YMOSL.mjs";
6
+ import "./chunk-HKHGJ6WS.mjs";
7
7
  export {
8
8
  formatSelectedDate
9
9
  };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange,
3
3
  export { alignCenter, alignEnd, alignStart, constrainStart, constrainValue } from './constrain.js';
4
4
  export { parseDateString } from './conversion.js';
5
5
  export { getEndDate, getUnitDuration } from './duration.js';
6
+ export { formatDate } from './format-date.js';
6
7
  export { formatRange } from './format-range.js';
7
8
  export { formatSelectedDate } from './format-selected-date.js';
8
9
  export { formatVisibleRange } from './format-visible-range.js';
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ __export(src_exports, {
27
27
  alignStartDate: () => alignStartDate,
28
28
  constrainStart: () => constrainStart,
29
29
  constrainValue: () => constrainValue,
30
+ formatDate: () => formatDate,
30
31
  formatRange: () => formatRange,
31
32
  formatSelectedDate: () => formatSelectedDate,
32
33
  formatVisibleRange: () => formatVisibleRange,
@@ -216,6 +217,12 @@ function getEndDate(startDate, duration) {
216
217
  return startDate.add(d);
217
218
  }
218
219
 
220
+ // src/format-date.ts
221
+ function formatDate(date, formatString, locale, timeZone = "UTC") {
222
+ const nativeDate = date.toDate(timeZone);
223
+ return formatString.replace(/yyyy/gi, nativeDate.toLocaleString(locale, { year: "numeric", timeZone })).replace(/yy/gi, nativeDate.toLocaleString(locale, { year: "2-digit", timeZone })).replace(/dd/gi, nativeDate.toLocaleString(locale, { day: "2-digit", timeZone })).replace(/d/gi, nativeDate.toLocaleString(locale, { day: "numeric", timeZone })).replace(/mmmm/gi, nativeDate.toLocaleString(locale, { month: "long", timeZone })).replace(/mmm/gi, nativeDate.toLocaleString(locale, { month: "short", timeZone })).replace(/mm/gi, nativeDate.toLocaleString(locale, { month: "2-digit", timeZone })).replace(/m/gi, nativeDate.toLocaleString(locale, { month: "numeric", timeZone }));
224
+ }
225
+
219
226
  // src/format-range.ts
220
227
  function formatRange(startDate, endDate, formatter, toString, timeZone) {
221
228
  let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
@@ -619,6 +626,7 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
619
626
  alignStartDate,
620
627
  constrainStart,
621
628
  constrainValue,
629
+ formatDate,
622
630
  formatRange,
623
631
  formatSelectedDate,
624
632
  formatVisibleRange,
package/dist/index.mjs CHANGED
@@ -28,6 +28,9 @@ import {
28
28
  getSectionEnd,
29
29
  getSectionStart
30
30
  } from "./chunk-VTFZA34K.mjs";
31
+ import {
32
+ formatVisibleRange
33
+ } from "./chunk-CAYCTIEJ.mjs";
31
34
  import {
32
35
  getDecadeRange
33
36
  } from "./chunk-G4VVKINZ.mjs";
@@ -35,10 +38,13 @@ import {
35
38
  getDaysInWeek,
36
39
  getMonthDays
37
40
  } from "./chunk-KFJ757ZA.mjs";
41
+ import "./chunk-SI75FOJ2.mjs";
42
+ import {
43
+ getMonthFormatter
44
+ } from "./chunk-LGEGBP3O.mjs";
38
45
  import {
39
46
  getMonthNames
40
47
  } from "./chunk-5HGHDJ3L.mjs";
41
- import "./chunk-SI75FOJ2.mjs";
42
48
  import {
43
49
  alignDate,
44
50
  alignStartDate
@@ -68,21 +74,18 @@ import {
68
74
  getUnitDuration
69
75
  } from "./chunk-ZSLC7OI2.mjs";
70
76
  import {
71
- formatSelectedDate
72
- } from "./chunk-LQAXQPWP.mjs";
77
+ formatDate
78
+ } from "./chunk-J22B5EMX.mjs";
73
79
  import {
74
- formatRange
75
- } from "./chunk-HKHGJ6WS.mjs";
76
- import {
77
- formatVisibleRange
78
- } from "./chunk-CAYCTIEJ.mjs";
79
- import {
80
- getMonthFormatter
81
- } from "./chunk-LGEGBP3O.mjs";
80
+ formatSelectedDate
81
+ } from "./chunk-LOHO72U6.mjs";
82
82
  import {
83
83
  getDayFormatter
84
84
  } from "./chunk-ODG5YF5H.mjs";
85
85
  import "./chunk-KN3YMOSL.mjs";
86
+ import {
87
+ formatRange
88
+ } from "./chunk-HKHGJ6WS.mjs";
86
89
  export {
87
90
  alignCenter,
88
91
  alignDate,
@@ -91,6 +94,7 @@ export {
91
94
  alignStartDate,
92
95
  constrainStart,
93
96
  constrainValue,
97
+ formatDate,
94
98
  formatRange,
95
99
  formatSelectedDate,
96
100
  formatVisibleRange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/date-utils",
3
- "version": "0.0.0-dev-20230321203218",
3
+ "version": "0.0.0-dev-20230326221705",
4
4
  "description": "Date utilities for zag.js",
5
5
  "keywords": [
6
6
  "js",
@@ -1,9 +1,9 @@
1
- import {
2
- formatRange
3
- } from "./chunk-HKHGJ6WS.mjs";
4
1
  import {
5
2
  getDayFormatter
6
3
  } from "./chunk-ODG5YF5H.mjs";
4
+ import {
5
+ formatRange
6
+ } from "./chunk-HKHGJ6WS.mjs";
7
7
 
8
8
  // src/format-selected-date.ts
9
9
  import { isSameDay } from "@internationalized/date";