@formkit/tempo 0.0.18 → 0.1.0
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/addDay.d.ts +9 -0
- package/dist/addDay.mjs +11 -0
- package/dist/addDay.mjs.map +1 -0
- package/dist/addHour.d.ts +9 -0
- package/dist/addHour.mjs +11 -0
- package/dist/addHour.mjs.map +1 -0
- package/dist/addMinute.d.ts +9 -0
- package/dist/addMinute.mjs +11 -0
- package/dist/addMinute.mjs.map +1 -0
- package/dist/addMonth.d.ts +13 -0
- package/dist/addMonth.mjs +19 -0
- package/dist/addMonth.mjs.map +1 -0
- package/dist/addSecond.d.ts +9 -0
- package/dist/addSecond.mjs +11 -0
- package/dist/addSecond.mjs.map +1 -0
- package/dist/addYear.d.ts +13 -0
- package/dist/addYear.mjs +19 -0
- package/dist/addYear.mjs.map +1 -0
- package/dist/ap.d.ts +8 -0
- package/dist/ap.mjs +28 -0
- package/dist/ap.mjs.map +1 -0
- package/dist/applyOffset.d.ts +11 -0
- package/dist/applyOffset.mjs +20 -0
- package/dist/applyOffset.mjs.map +1 -0
- package/dist/bundle.mjs +1215 -0
- package/dist/bundle.mjs.map +1 -0
- package/dist/common.d.ts +137 -0
- package/dist/common.mjs +252 -0
- package/dist/common.mjs.map +1 -0
- package/dist/date.d.ts +9 -0
- package/dist/date.mjs +28 -0
- package/dist/date.mjs.map +1 -0
- package/dist/dayEnd.d.ts +9 -0
- package/dist/dayEnd.mjs +11 -0
- package/dist/dayEnd.mjs.map +1 -0
- package/dist/dayOfYear.d.ts +10 -0
- package/dist/dayOfYear.mjs +12 -0
- package/dist/dayOfYear.mjs.map +1 -0
- package/dist/dayStart.d.ts +9 -0
- package/dist/dayStart.mjs +11 -0
- package/dist/dayStart.mjs.map +1 -0
- package/dist/deviceLocale.d.ts +7 -0
- package/dist/deviceLocale.mjs +8 -0
- package/dist/deviceLocale.mjs.map +1 -0
- package/dist/deviceTZ.d.ts +8 -0
- package/dist/deviceTZ.mjs +8 -0
- package/dist/deviceTZ.mjs.map +1 -0
- package/dist/diffDays.d.ts +12 -0
- package/dist/diffDays.mjs +14 -0
- package/dist/diffDays.mjs.map +1 -0
- package/dist/diffHours.d.ts +12 -0
- package/dist/diffHours.mjs +14 -0
- package/dist/diffHours.mjs.map +1 -0
- package/dist/diffMilliseconds.d.ts +10 -0
- package/dist/diffMilliseconds.mjs +11 -0
- package/dist/diffMilliseconds.mjs.map +1 -0
- package/dist/diffMinutes.d.ts +11 -0
- package/dist/diffMinutes.mjs +10 -0
- package/dist/diffMinutes.mjs.map +1 -0
- package/dist/diffMonths.d.ts +10 -0
- package/dist/diffMonths.mjs +25 -0
- package/dist/diffMonths.mjs.map +1 -0
- package/dist/diffRound.d.ts +9 -0
- package/dist/diffRound.mjs +9 -0
- package/dist/diffRound.mjs.map +1 -0
- package/dist/diffSeconds.d.ts +12 -0
- package/dist/diffSeconds.mjs +10 -0
- package/dist/diffSeconds.mjs.map +1 -0
- package/dist/diffWeeks.d.ts +12 -0
- package/dist/diffWeeks.mjs +14 -0
- package/dist/diffWeeks.mjs.map +1 -0
- package/dist/diffYears.d.ts +10 -0
- package/dist/diffYears.mjs +10 -0
- package/dist/diffYears.mjs.map +1 -0
- package/dist/format.d.ts +36 -0
- package/dist/format.mjs +48 -0
- package/dist/format.mjs.map +1 -0
- package/dist/formatStr.d.ts +13 -0
- package/dist/formatStr.mjs +13 -0
- package/dist/formatStr.mjs.map +1 -0
- package/dist/fourDigitYear.d.ts +10 -0
- package/dist/fourDigitYear.mjs +12 -0
- package/dist/fourDigitYear.mjs.map +1 -0
- package/dist/hourEnd.d.ts +9 -0
- package/dist/hourEnd.mjs +11 -0
- package/dist/hourEnd.mjs.map +1 -0
- package/dist/hourStart.d.ts +9 -0
- package/dist/hourStart.mjs +11 -0
- package/dist/hourStart.mjs.map +1 -0
- package/dist/index.cjs +140 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -4
- package/dist/index.d.ts +54 -498
- package/dist/index.mjs +62 -1057
- package/dist/index.mjs.map +1 -1
- package/dist/isAfter.d.ts +18 -0
- package/dist/isAfter.mjs +11 -0
- package/dist/isAfter.mjs.map +1 -0
- package/dist/isBefore.d.ts +13 -0
- package/dist/isBefore.mjs +11 -0
- package/dist/isBefore.mjs.map +1 -0
- package/dist/isEqual.d.ts +13 -0
- package/dist/isEqual.mjs +11 -0
- package/dist/isEqual.mjs.map +1 -0
- package/dist/iso8601.d.ts +13 -0
- package/dist/iso8601.mjs +27 -0
- package/dist/iso8601.mjs.map +1 -0
- package/dist/minuteEnd.d.ts +9 -0
- package/dist/minuteEnd.mjs +11 -0
- package/dist/minuteEnd.mjs.map +1 -0
- package/dist/minuteStart.d.ts +9 -0
- package/dist/minuteStart.mjs +11 -0
- package/dist/minuteStart.mjs.map +1 -0
- package/dist/monthDays.d.ts +9 -0
- package/dist/monthDays.mjs +10 -0
- package/dist/monthDays.mjs.map +1 -0
- package/dist/monthEnd.d.ts +10 -0
- package/dist/monthEnd.mjs +13 -0
- package/dist/monthEnd.mjs.map +1 -0
- package/dist/monthStart.d.ts +9 -0
- package/dist/monthStart.mjs +12 -0
- package/dist/monthStart.mjs.map +1 -0
- package/dist/nearestDay.d.ts +12 -0
- package/dist/nearestDay.mjs +46 -0
- package/dist/nearestDay.mjs.map +1 -0
- package/dist/offset.d.ts +14 -0
- package/dist/offset.mjs +36 -0
- package/dist/offset.mjs.map +1 -0
- package/dist/parse.d.ts +13 -0
- package/dist/parse.mjs +163 -0
- package/dist/parse.mjs.map +1 -0
- package/dist/parts.d.ts +12 -0
- package/dist/parts.mjs +214 -0
- package/dist/parts.mjs.map +1 -0
- package/dist/range.d.ts +10 -0
- package/dist/range.mjs +50 -0
- package/dist/range.mjs.map +1 -0
- package/dist/removeOffset.d.ts +10 -0
- package/dist/removeOffset.mjs +13 -0
- package/dist/removeOffset.mjs.map +1 -0
- package/dist/sameDay.d.ts +10 -0
- package/dist/sameDay.mjs +11 -0
- package/dist/sameDay.mjs.map +1 -0
- package/dist/sameHour.d.ts +10 -0
- package/dist/sameHour.mjs +11 -0
- package/dist/sameHour.mjs.map +1 -0
- package/dist/sameMinute.d.ts +10 -0
- package/dist/sameMinute.mjs +11 -0
- package/dist/sameMinute.mjs.map +1 -0
- package/dist/sameSecond.d.ts +10 -0
- package/dist/sameSecond.mjs +11 -0
- package/dist/sameSecond.mjs.map +1 -0
- package/dist/sameYear.d.ts +10 -0
- package/dist/sameYear.mjs +11 -0
- package/dist/sameYear.mjs.map +1 -0
- package/dist/types.d.ts +143 -0
- package/dist/types.mjs +1 -0
- package/dist/types.mjs.map +1 -0
- package/dist/tzDate.d.ts +15 -0
- package/dist/tzDate.mjs +12 -0
- package/dist/tzDate.mjs.map +1 -0
- package/dist/weekEnd.d.ts +12 -0
- package/dist/weekEnd.mjs +12 -0
- package/dist/weekEnd.mjs.map +1 -0
- package/dist/weekStart.d.ts +12 -0
- package/dist/weekStart.mjs +15 -0
- package/dist/weekStart.mjs.map +1 -0
- package/dist/yearDays.d.ts +9 -0
- package/dist/yearDays.mjs +10 -0
- package/dist/yearDays.mjs.map +1 -0
- package/dist/yearEnd.d.ts +9 -0
- package/dist/yearEnd.mjs +13 -0
- package/dist/yearEnd.mjs.map +1 -0
- package/dist/yearStart.d.ts +9 -0
- package/dist/yearStart.mjs +13 -0
- package/dist/yearStart.mjs.map +1 -0
- package/package.json +8 -1
package/dist/addDay.d.ts
ADDED
package/dist/addDay.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addDay.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n days after the original one.\n * @param inputDate - A date to increment by 1 day.\n */\nexport function addDay(inputDate: DateInput, count = 1) {\n const d = date(inputDate)\n d.setDate(d.getDate() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,OAAO,WAAsB,QAAQ,GAAG;AACtD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,QAAQ,EAAE,QAAQ,IAAI,KAAK;AAC7B,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new date object 1/n hours after the original one.
|
|
5
|
+
* @param inputDate - A date to increment by 1 day.
|
|
6
|
+
*/
|
|
7
|
+
declare function addHour(inputDate: DateInput, count?: number): Date;
|
|
8
|
+
|
|
9
|
+
export { addHour };
|
package/dist/addHour.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addHour.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n hours after the original one.\n * @param inputDate - A date to increment by 1 day.\n */\nexport function addHour(inputDate: DateInput, count = 1) {\n const d = date(inputDate)\n d.setHours(d.getHours() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,QAAQ,WAAsB,QAAQ,GAAG;AACvD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,SAAS,EAAE,SAAS,IAAI,KAAK;AAC/B,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new date object 1/n seconds after the original one.
|
|
5
|
+
* @param inputDate - A date to increment by 1 day.
|
|
6
|
+
*/
|
|
7
|
+
declare function addMinute(inputDate: DateInput, count?: number): Date;
|
|
8
|
+
|
|
9
|
+
export { addMinute };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addMinute.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n seconds after the original one.\n * @param inputDate - A date to increment by 1 day.\n */\nexport function addMinute(inputDate: DateInput, count = 1) {\n const d = date(inputDate)\n d.setMinutes(d.getMinutes() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAAsB,QAAQ,GAAG;AACzD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,EAAE,WAAW,IAAI,KAAK;AACnC,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new date object 1/n months after the original one. Keep in mind if you
|
|
5
|
+
* start with a date late in a given month you could get a date after the next
|
|
6
|
+
* month.
|
|
7
|
+
* @param inputDate - A date to increment by 1 or more months.
|
|
8
|
+
* @param count - The quantity to add.
|
|
9
|
+
* @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
|
|
10
|
+
*/
|
|
11
|
+
declare function addMonth(inputDate: DateInput, count?: number, dateOverflow?: boolean): Date;
|
|
12
|
+
|
|
13
|
+
export { addMonth };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/addMonth.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
import { monthDays } from "./monthDays.mjs";
|
|
4
|
+
function addMonth(inputDate, count = 1, dateOverflow = false) {
|
|
5
|
+
const d = date(inputDate);
|
|
6
|
+
const dayOfMonth = d.getDate();
|
|
7
|
+
if (!dateOverflow)
|
|
8
|
+
d.setDate(1);
|
|
9
|
+
d.setMonth(d.getMonth() + count);
|
|
10
|
+
if (!dateOverflow) {
|
|
11
|
+
const daysInMonth = monthDays(d);
|
|
12
|
+
d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth);
|
|
13
|
+
}
|
|
14
|
+
return d;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
addMonth
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=addMonth.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addMonth.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n months after the original one. Keep in mind if you\n * start with a date late in a given month you could get a date after the next\n * month.\n * @param inputDate - A date to increment by 1 or more months.\n * @param count - The quantity to add.\n * @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.\n */\nexport function addMonth(\n inputDate: DateInput,\n count = 1,\n dateOverflow = false\n) {\n const d = date(inputDate)\n const dayOfMonth = d.getDate()\n // If overflowing is disallowed, set the date back to the first of the month\n if (!dateOverflow) d.setDate(1)\n d.setMonth(d.getMonth() + count)\n\n // If overflowing is disallowed, we need to set the date back to the proper\n // day or the last day of the month.\n if (!dateOverflow) {\n const daysInMonth = monthDays(d)\n d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth)\n }\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAWnB,SAAS,SACd,WACA,QAAQ,GACR,eAAe,OACf;AACA,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,aAAa,EAAE,QAAQ;AAE7B,MAAI,CAAC;AAAc,MAAE,QAAQ,CAAC;AAC9B,IAAE,SAAS,EAAE,SAAS,IAAI,KAAK;AAI/B,MAAI,CAAC,cAAc;AACjB,UAAM,cAAc,UAAU,CAAC;AAC/B,MAAE,QAAQ,cAAc,aAAa,cAAc,UAAU;AAAA,EAC/D;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new date object 1/n seconds after the original one.
|
|
5
|
+
* @param inputDate - A date to increment by 1 day.
|
|
6
|
+
*/
|
|
7
|
+
declare function addSecond(inputDate: DateInput, count?: number): Date;
|
|
8
|
+
|
|
9
|
+
export { addSecond };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addSecond.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n seconds after the original one.\n * @param inputDate - A date to increment by 1 day.\n */\nexport function addSecond(inputDate: DateInput, count = 1) {\n const d = date(inputDate)\n d.setSeconds(d.getSeconds() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAAsB,QAAQ,GAAG;AACzD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,EAAE,WAAW,IAAI,KAAK;AACnC,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new date object 1/n years after the original one. Keep in mind if
|
|
5
|
+
* you start with a date late in a given month you could get a date after the
|
|
6
|
+
* next month.
|
|
7
|
+
* @param inputDate - A date to increment by 1 day.
|
|
8
|
+
* @param count - The quantity of years add.
|
|
9
|
+
* @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
|
|
10
|
+
*/
|
|
11
|
+
declare function addYear(inputDate: DateInput, count?: number, dateOverflow?: boolean): Date;
|
|
12
|
+
|
|
13
|
+
export { addYear };
|
package/dist/addYear.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/addYear.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
import { monthDays } from "./monthDays.mjs";
|
|
4
|
+
function addYear(inputDate, count = 1, dateOverflow = false) {
|
|
5
|
+
const d = date(inputDate);
|
|
6
|
+
const dayOfMonth = d.getDate();
|
|
7
|
+
if (!dateOverflow)
|
|
8
|
+
d.setDate(1);
|
|
9
|
+
d.setFullYear(d.getFullYear() + count);
|
|
10
|
+
if (!dateOverflow) {
|
|
11
|
+
const daysInMonth = monthDays(d);
|
|
12
|
+
d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth);
|
|
13
|
+
}
|
|
14
|
+
return d;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
addYear
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=addYear.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addYear.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n years after the original one. Keep in mind if\n * you start with a date late in a given month you could get a date after the\n * next month.\n * @param inputDate - A date to increment by 1 day.\n * @param count - The quantity of years add.\n * @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.\n */\nexport function addYear(inputDate: DateInput, count = 1, dateOverflow = false) {\n const d = date(inputDate)\n const dayOfMonth = d.getDate()\n // If overflowing is disallowed, set the date back to the first of the month\n if (!dateOverflow) d.setDate(1)\n\n d.setFullYear(d.getFullYear() + count)\n\n // If overflowing is disallowed, we need to set the date back to the proper\n // day or the last day of the month.\n if (!dateOverflow) {\n const daysInMonth = monthDays(d)\n d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth)\n }\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAWnB,SAAS,QAAQ,WAAsB,QAAQ,GAAG,eAAe,OAAO;AAC7E,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,aAAa,EAAE,QAAQ;AAE7B,MAAI,CAAC;AAAc,MAAE,QAAQ,CAAC;AAE9B,IAAE,YAAY,EAAE,YAAY,IAAI,KAAK;AAIrC,MAAI,CAAC,cAAc;AACjB,UAAM,cAAc,UAAU,CAAC;AAC/B,MAAE,QAAQ,cAAc,aAAa,cAAc,UAAU;AAAA,EAC/D;AACA,SAAO;AACT;","names":[]}
|
package/dist/ap.d.ts
ADDED
package/dist/ap.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/ap.ts
|
|
2
|
+
import { dayPeriodMap, specDate, normStr } from "./common.mjs";
|
|
3
|
+
function ap(ampm, locale) {
|
|
4
|
+
const l = dayPeriodMap.get(locale);
|
|
5
|
+
if (l && l[ampm])
|
|
6
|
+
return l[ampm];
|
|
7
|
+
const specimen = new Date(specDate);
|
|
8
|
+
specimen.setUTCHours(ampm === "am" ? 5 : 20);
|
|
9
|
+
const subparts = new Intl.DateTimeFormat(locale, {
|
|
10
|
+
timeStyle: "full",
|
|
11
|
+
timeZone: "UTC",
|
|
12
|
+
hour12: true
|
|
13
|
+
}).formatToParts(specimen).map(normStr);
|
|
14
|
+
const period = subparts.find((part) => part.type === "dayPeriod");
|
|
15
|
+
if (period) {
|
|
16
|
+
const localePeriods = l || {};
|
|
17
|
+
dayPeriodMap.set(
|
|
18
|
+
locale,
|
|
19
|
+
Object.assign(localePeriods, { [ampm]: period.value })
|
|
20
|
+
);
|
|
21
|
+
return period.value;
|
|
22
|
+
}
|
|
23
|
+
return ampm;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
ap
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=ap.mjs.map
|
package/dist/ap.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ap.ts"],"sourcesContent":["import { dayPeriodMap, specDate, normStr } from \"./common\"\n\n/**\n * Determines the correct value for am/pm by locale and memoizes it.\n * @param ampm - am or pm\n * @param locale - The locale to fetch.\n */\nexport function ap(ampm: \"am\" | \"pm\", locale: string): string {\n const l = dayPeriodMap.get(locale)\n if (l && l[ampm]) return l[ampm] as string\n const specimen = new Date(specDate)\n specimen.setUTCHours(ampm === \"am\" ? 5 : 20)\n const subparts = new Intl.DateTimeFormat(locale, {\n timeStyle: \"full\",\n timeZone: \"UTC\",\n hour12: true,\n })\n .formatToParts(specimen)\n .map(normStr)\n const period = subparts.find((part) => part.type === \"dayPeriod\")\n if (period) {\n const localePeriods: { am?: string; pm?: string } = l || {}\n dayPeriodMap.set(\n locale,\n Object.assign(localePeriods, { [ampm]: period.value })\n )\n return period.value\n }\n return ampm\n}\n"],"mappings":";AAAA,SAAS,cAAc,UAAU,eAAe;AAOzC,SAAS,GAAG,MAAmB,QAAwB;AAC5D,QAAM,IAAI,aAAa,IAAI,MAAM;AACjC,MAAI,KAAK,EAAE,IAAI;AAAG,WAAO,EAAE,IAAI;AAC/B,QAAM,WAAW,IAAI,KAAK,QAAQ;AAClC,WAAS,YAAY,SAAS,OAAO,IAAI,EAAE;AAC3C,QAAM,WAAW,IAAI,KAAK,eAAe,QAAQ;AAAA,IAC/C,WAAW;AAAA,IACX,UAAU;AAAA,IACV,QAAQ;AAAA,EACV,CAAC,EACE,cAAc,QAAQ,EACtB,IAAI,OAAO;AACd,QAAM,SAAS,SAAS,KAAK,CAAC,SAAS,KAAK,SAAS,WAAW;AAChE,MAAI,QAAQ;AACV,UAAM,gBAA8C,KAAK,CAAC;AAC1D,iBAAa;AAAA,MACX;AAAA,MACA,OAAO,OAAO,eAAe,EAAE,CAAC,IAAI,GAAG,OAAO,MAAM,CAAC;AAAA,IACvD;AACA,WAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Apply a given offset to a date, returning a new date with the offset
|
|
5
|
+
* applied by adding or subtracting the given number of minutes.
|
|
6
|
+
* @param dateInput - The date to apply the offset to.
|
|
7
|
+
* @param offset - The offset to apply in the +-HHmm or +-HH:mm format.
|
|
8
|
+
*/
|
|
9
|
+
declare function applyOffset(dateInput: DateInput, offset?: string): Date;
|
|
10
|
+
|
|
11
|
+
export { applyOffset };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/applyOffset.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
import { fixedLengthByOffset, offsetToMins } from "./common.mjs";
|
|
4
|
+
function applyOffset(dateInput, offset = "+00:00") {
|
|
5
|
+
const d = date(dateInput);
|
|
6
|
+
const token = (() => {
|
|
7
|
+
switch (fixedLengthByOffset(offset)) {
|
|
8
|
+
case 5:
|
|
9
|
+
return "ZZ";
|
|
10
|
+
case 6:
|
|
11
|
+
return "Z";
|
|
12
|
+
}
|
|
13
|
+
})();
|
|
14
|
+
const timeDiffInMins = offsetToMins(offset, token);
|
|
15
|
+
return new Date(d.getTime() + timeDiffInMins * 1e3 * 60);
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
applyOffset
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=applyOffset.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/applyOffset.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { TimezoneToken, fixedLengthByOffset, offsetToMins } from \"./common\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Apply a given offset to a date, returning a new date with the offset\n * applied by adding or subtracting the given number of minutes.\n * @param dateInput - The date to apply the offset to.\n * @param offset - The offset to apply in the +-HHmm or +-HH:mm format.\n */\nexport function applyOffset(dateInput: DateInput, offset = \"+00:00\"): Date {\n const d = date(dateInput)\n const token = ((): TimezoneToken => {\n switch (fixedLengthByOffset(offset)) {\n case 5:\n return \"ZZ\"\n case 6:\n return \"Z\"\n }\n })()\n const timeDiffInMins = offsetToMins(offset, token)\n return new Date(d.getTime() + timeDiffInMins * 1000 * 60)\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAwB,qBAAqB,oBAAoB;AAS1D,SAAS,YAAY,WAAsB,SAAS,UAAgB;AACzE,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,SAAS,MAAqB;AAClC,YAAQ,oBAAoB,MAAM,GAAG;AAAA,MACnC,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,IACX;AAAA,EACF,GAAG;AACH,QAAM,iBAAiB,aAAa,QAAQ,KAAK;AACjD,SAAO,IAAI,KAAK,EAAE,QAAQ,IAAI,iBAAiB,MAAO,EAAE;AAC1D;","names":[]}
|