-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59db3ef
commit 0275358
Showing
11 changed files
with
355 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
<script lang="ts" setup> | ||
const fns = { | ||
addDay: { | ||
description: | ||
"Returns a new Date object with a positive or negative number of days applied to date argument. To subtract days, use a negative number.", | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "amount", | ||
type: "number", | ||
}, | ||
], | ||
}, | ||
addHour: { | ||
description: | ||
"Returns a new Date object with a positive or negative number of hours applied to date argument. To subtract hours, use a negative number.", | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "amount", | ||
type: "number", | ||
}, | ||
], | ||
}, | ||
addMinute: { | ||
description: | ||
"Returns a new Date object with a positive or negative number of minutes applied to date argument. To subtract minutes, use a negative number.", | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "amount", | ||
type: "number", | ||
}, | ||
], | ||
}, | ||
addMonth: { | ||
description: `Returns a new Date object with a positive or negative number of | ||
months applied to date argument. To subtract months, use a negative number. | ||
Sometimes the result will "overflow" the available days of | ||
the result month. For example when adding 1 month to January 31st the | ||
resulting date would be February 31st, which does not exist. By default, the | ||
date will be set to the last day of February but you could opt for it | ||
to "overflow" into March by setting <code>dateOverflow</code> to | ||
<code>true</code>.`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "amount", | ||
type: "number", | ||
}, | ||
{ | ||
name: "dateOverflow", | ||
type: "boolean", | ||
}, | ||
], | ||
}, | ||
addSecond: { | ||
description: | ||
"Returns a new Date object with a positive or negative number of seconds applied to date argument. To subtract seconds, use a negative number.", | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "amount", | ||
type: "number", | ||
}, | ||
], | ||
}, | ||
addYear: { | ||
description: `Returns a new Date object with a positive or negative number of years | ||
applied to date argument. To subtract years, use a negative number. | ||
Sometimes the result will "overflow" the available days of | ||
the result month. For example when adding 1 year to February 29, 2024 the | ||
resulting date would be February 29, 2025, which does not exist (2025 is | ||
not a leap year). By default, the date will be set to February 28, 2025 but | ||
you could opt for it to "overflow" into March by setting | ||
<code>dateOverflow</code> to <code>true</code>.`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "amount", | ||
type: "number", | ||
}, | ||
{ | ||
name: "dateOverflow", | ||
type: "boolean", | ||
}, | ||
], | ||
}, | ||
applyOffset: { | ||
description: `Returns a new Date object with a timezone offset applied to date argument | ||
— this function does fundamentally change the date but can be very useful | ||
when working with timezones. Read more in the timezone section.`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "offset", | ||
type: "string", | ||
comment: "+-HHmm, ex: -0800", | ||
}, | ||
], | ||
}, | ||
dayStart: { | ||
description: `Returns a new Date object with the time set to 00:00:00.000 (local time).`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
], | ||
}, | ||
dayEnd: { | ||
description: `Returns a new Date object with the time set to 23:59:59 (local).`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
], | ||
}, | ||
monthEnd: { | ||
description: `Returns a new Date object with the date set to the last day of the current month (does not modify the time).`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
], | ||
}, | ||
monthStart: { | ||
description: `Returns a new Date object with the date set to the first day of the current month and the time set to 00:00:00 (local).`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
], | ||
}, | ||
removeOffset: { | ||
description: `Returns a new Date object with the inverse of the specified timezone offset removed. This can be helpful to normalize time information across timezones.`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "offset", | ||
type: "string", | ||
comment: "+-HHmm, ex: -0800", | ||
}, | ||
], | ||
}, | ||
weekStart: { | ||
description: `Returns a new Date object with the date set to the first day of the current week with the time set to 00:00:00 (local).`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "startOfWeekDay", | ||
type: "number", | ||
comment: "0-6, 0 is Sunday", | ||
}, | ||
], | ||
}, | ||
weekEnd: { | ||
description: `Returns a new Date object with the date set to the last day of the current week with the time set to 23:59:59 (local).`, | ||
return: "Date", | ||
arguments: [ | ||
{ | ||
name: "date", | ||
type: "string | Date", | ||
}, | ||
{ | ||
name: "startOfWeekDay", | ||
type: "number", | ||
comment: "0-6, 0 is Sunday", | ||
}, | ||
], | ||
}, | ||
} | ||
</script> | ||
|
||
<template> | ||
<PageSection id="modify"> | ||
<HeadingSection title="Modify" class="text-sky-500" /> | ||
<p> | ||
Tempo includes a number of (tree-shakable) utility functions to assist you | ||
in your date modifying needs. These functions all accept either an ISO | ||
8601 string or a Date object and return a <em>new Date object</em> (they | ||
do not change the date argument). | ||
</p> | ||
<div v-for="(def, fn) in fns"> | ||
<h4>{{ fn }}</h4> | ||
<p v-html="def.description" /> | ||
<FunctionReference | ||
:function="fn" | ||
:arguments="def.arguments" | ||
:return="def.return" | ||
/> | ||
</div> | ||
</PageSection> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { parse } from "@formkit/tempo" | ||
|
||
// Nov 31 does not exist! | ||
const date = "2011-11-31" | ||
|
||
// Overflows can throw an error | ||
parse({ | ||
date, | ||
format: "YYYY-MM-DD", | ||
locale: "en-US", | ||
dateOverflow: "throw", | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { parse } from "@formkit/tempo" | ||
|
||
// Nov 31 does not exist! | ||
const date = "2011-11-31" | ||
|
||
// Default overflow is "backward" | ||
parse(date, "YYYY-MM-DD", "en-US") | ||
|
||
// Parse "forward" into December | ||
parse({ | ||
date, | ||
format: "YYYY-MM-DD", | ||
locale: "en-US", | ||
dateOverflow: "forward", | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { date } from "./date" | ||
|
||
/** | ||
* Returns a new date object 1/n hours after the original one. | ||
* @param inputDate - A date to increment by 1 day. | ||
*/ | ||
export function addHour(inputDate: DateInput, count = 1) { | ||
const d = date(inputDate) | ||
d.setHours(d.getHours() + count) | ||
return d | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { date } from "./date" | ||
|
||
/** | ||
* Returns a new date object 1/n seconds after the original one. | ||
* @param inputDate - A date to increment by 1 day. | ||
*/ | ||
export function addMinute(inputDate: DateInput, count = 1) { | ||
const d = date(inputDate) | ||
d.setMinutes(d.getMinutes() + count) | ||
return d | ||
} |
Oops, something went wrong.