### Install Tempo Source: https://tempo.formkit.com/ Instructions on how to install the Tempo library using npm or yarn. ```APIDOC ## Install Tempo Tempo is a collection of functions that can be imported from the `@formkit/tempo` package. This approach is beneficial for tree shaking, ensuring only the necessary code is included in your project. ### Installation Command ```bash npm install @formkit/tempo ``` ```bash yarn add @formkit/tempo ``` ``` -------------------------------- ### Set Date to Start of Day with Tempo Source: https://tempo.formkit.com/ Use `dayStart` to get a new Date object with the time set to 00:00:00.000 in local time. ```javascript function dayStart( date: string | Date ): Date ``` -------------------------------- ### Get Format Token String Source: https://tempo.formkit.com/ Returns the token format string for a given style and locale. ```typescript import { formatStr } from "@formkit/tempo" formatStr("long", "en") formatStr("long", "ja") ``` -------------------------------- ### Get Localized AM/PM String Source: https://tempo.formkit.com/ Returns the localized string for AM or PM based on the provided locale. ```typescript import { ap } from "@formkit/tempo" ap("am", "ja") ``` -------------------------------- ### Set Date to End of Day with Tempo Source: https://tempo.formkit.com/ Use `dayEnd` to get a new Date object with the time set to 23:59:59.999 in local time. ```javascript function dayEnd( date: string | Date ): Date ``` -------------------------------- ### Set Time to End of Hour with Tempo Source: https://tempo.formkit.com/ Use `hourEnd` to get a new Date object with the minutes part of the time set to 59:59.999 in local time. ```javascript function hourEnd( date: string | Date ): Date ``` -------------------------------- ### Get locale-specific date ranges Source: https://tempo.formkit.com/ Use the range function to get an array of options for a given token and locale. For example, `MMMM` in `en-US` returns month names. ```javascript import { range } from "@formkit/tempo" range("dddd", "en") range("MMMM", "zh") range("MMMM", "ar") ``` -------------------------------- ### Date Manipulation Functions Source: https://tempo.formkit.com/ Functions to adjust Date objects to the start or end of specific time periods or apply timezone transformations. ```APIDOC ## hourStart ### Description Returns a new Date object with the minutes part of the time set to 00:00.000 (local time). ## minuteEnd ### Description Returns a new Date object with the seconds part of the time set to 59.999 (local time). ## monthEnd ### Description Returns a new Date object with the date set to the last day of the current month (does not modify the time). ## removeOffset ### Description Returns a new Date object with the inverse of the specified offset applied. ### Parameters - **date** (string | Date) - Required - **offset** (string) - Required - +-HHmm, ex: -0800 ## tzDate ### Description Converts an ISO 8601 like string into a Date object with a timezone applied. ### Parameters - **date** (string | Date) - Required - **tz** (string) - Required - IANA timezone, ex: "America/Los_Angeles" ``` -------------------------------- ### range Source: https://tempo.formkit.com/ Returns an array of options for a given token in a given locale. ```APIDOC ## range ### Description Returns an array of options for a given token in a given locale (e.g., month names or day names). ### Parameters #### Arguments - **token** (string) - Required - The format token (e.g., 'MMMM', 'dddd'). - **locale** (string) - Required - The locale code (default: 'en'). - **genitive** (boolean) - Optional - Whether to use genitive case (default: false). ### Response - **Returns** (string[]) - An array of strings representing the requested date parts. ``` -------------------------------- ### Format Dates Source: https://tempo.formkit.com/ Learn how to format dates using Tempo's `format()` function, supporting both format styles and custom tokens. ```APIDOC ## Format Dates The `format()` function in Tempo allows you to output dates in various human-readable formats. It supports internationalization through locale-aware formatting styles and custom formatting tokens. ### Function Signature ```typescript function format( date: Date | string, // Strings must be in ISO 8601 format format: string | object, locale?: string ): string ``` Or using an options object: ```typescript function format( options: FormatOptions ): string ``` ### Format Styles Tempo leverages `Intl.DateTimeFormat` to provide locale-sensitive date and time formatting. You can specify a date style to indicate the desired level of detail. **Date Styles:** | Style | Example (en) | Example (de) | Example (zh) | |--------|--------------------------|------------------------|----------------| | `full` | Sunday, April 19, 2026 | Sonntag, 19. April 2026 | 2026年4月19日星期日 | | `long` | April 19, 2026 | 19. April 2026 | 2026年4月19日 | | `medium`| Apr 19, 2026 | 19.04.2026 | 2026年4月19日 | | `short`| 4/19/26 | 19.04.26 | 2026/4/19 | **Example Usage:** ```javascript import { format } from "@formkit/tempo" const date = new Date() // Using date styles console.log(format(date, "full")) // e.g., "Sunday, April 19, 2026" console.log(format(date, { date: "long" })) // e.g., "April 19, 2026" console.log(format(date, "medium")) // e.g., "Apr 19, 2026" console.log(format(date, "short")) // e.g., "4/19/26" // With an explicit locale console.log(format(date, "full", "it")) // e.g., "domenica 19 aprile 2026" ``` **Note:** The `format()` function operates in the local timezone by default. For example, `2013-01-01T00:00:00Z` formatted in the US Eastern timezone will appear as `12/31/2012 7:00 PM`. ``` -------------------------------- ### dayStart Source: https://tempo.formkit.com/ Returns a new Date object with the time set to 00:00:00.000 (local time). ```APIDOC ## dayStart ### Description Returns a new Date object with the time set to 00:00:00.000 (local time). ### Method `dayStart` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { dayStart } from "@formkit/tempo" dayStart("2023-10-26T10:30:00Z") ``` ### Response #### Success Response (200) - **Date** (Date) - A new Date object representing the start of the day. #### Response Example ```json { "example": "2023-10-26T00:00:00.000Z" } ``` ``` -------------------------------- ### Import and Use Tempo Format and Parse Source: https://tempo.formkit.com/ Import the format and parse functions from @formkit/tempo to work with dates. The format function can take a Date object or ISO string and a format string, while parse does the reverse. ```javascript import { format, parse } from "@formkit/tempo" const readable = format(new Date(), "full") parse(readable, "full") ``` -------------------------------- ### Format Tokens Source: https://tempo.formkit.com/ Utilize format tokens for arbitrary date and time formatting, similar to day.js. These tokens respect the specified locale. ```APIDOC ## Format Tokens Tempo provides formatting tokens for creating custom date and time formats. These tokens are similar to those found in libraries like day.js and automatically utilize the user's locale or a specified locale. ### Available Tokens | Token | Example | Description | |---|---|---| | `YY` | 26 | 2 digit year | | `YYYY` | 2026 | 4 digit year | | `M` | 4 | The month 1-12 | | `MM` | 04 | The month 01-12 | | `MMM` | Apr | Short name Jan-Dec | | `MMMM` | April | Full name January - December | | `D` | 19 | The day of the month 1-31 | | `DD` | 19 | The day of the month 01-31 | | `d` | S | Single digit day "T" | | `ddd` | Sun | Short day name | | `dddd` | Sunday | Full day name Wednesday | | `H` | 1, 13 | Minimum hour digits, 24 hour, 0-23 | | `HH` | 01, 13 | 2 hour digits, 24 hour, 00-23 | | `h` | 1, 12 | Minimum hour digits, 12 hour clock, 1-12 | | `hh` | 01, 12 | 2 hour digits, 12 hour clock, 01-12 | | `m` | 2, 33 | The minute 0-59 | | `mm` | 02, 33 | The minute 00-59 | | `s` | 7, 17 | The second 0-59 | | `ss` | 07, 17 | The second 00-59 | | `SSS` | 007, 123, 789 | The millisecond, 3 digits (000-999). When parsing, accepts variable-length fractional seconds (1-9 digits). | | `a` | pm | am/pm | | `A` | PM | AM/PM | | `Z` | +08:00, +05:30, -05:32:11 | The timezone offset from GMT (`[+-]HH:mm[:ss]`). Seconds are included for historical timezones with sub-minute offsets. | | `ZZ` | +0800, +0530, -053211 | The timezone offset from GMT (`[+-]HHmm[ss]`). Seconds are included for historical timezones with sub-minute offsets. | ### Usage Examples ```javascript import { format } from "@formkit/tempo" const l = "en" const t = new Date() format(t, "YYYY-MM-DD", l) format(t, "MMM D, YYYY", l) format(t, "MMMM D, YYYY", l) format(t, "DD/MM/YYYY", l) format(t, "hh:mm:ss", l) format(t, "h:mm:ss a", l) format(t, "MMMM D, YYYY h:mm a", l) format(t, "dddd, MMMM D, YYYY", l) format(t, "M/D/YY", l) format(t, "h:mm:ss A", l) format(t, "YYYY-MM-DD HH:mm:ss", l) format(t, "MMM D, YYYY HH:mm", l) format(t, "dddd, MMMM D, YYYY h:mm:ss a", l) format(t, "h:mm A", l) format(t, "YYYY-MM-DDTHH:mm:ssZ", l) format(t, "YY-M-D", l) format(t, "YYYY/MM/DD", l) format(t, "MMM D, YYYY HH:mm:ss", l) format(t, "D MMMM YYYY", l) format(t, "HH:mm", l) format(t, "h:mm a Z", l) format(t, "dddd, MMMM D, YYYY h:mm A", l) format(t, "M/D/YYYY", l) format(t, "hh:mm:ss a Z", l) format(t, "YYYY-MM-DDTHH:mm:ss", l) format(t, "MMM D, YYYY h:mm A", l) format(t, "dddd, MMMM D, YYYY HH:mm:ss", l) format(t, "h:mm:ss A Z", l) format(t, "YY/MM/DD", l) format(t, "YYYY MMMM D", l) format(t, "M-D-YY", l) format(t, "HH:mm:ss.SSS", l) format(t, "YYYY-MM-DDTHH:mm:ss.SSSZ", l) ``` ``` -------------------------------- ### Function: parts Source: https://tempo.formkit.com/ Generates an array of part definitions based on a format string and locale. ```APIDOC ## parts ### Description Given a format and locale, this function produces an array of "parts". It accepts style formats and token formats and returns parts with granular data such as the part’s token and a regex to match for it. ### Parameters - **format** (string) - Required - The format string or style object (e.g., "YYYY-MM-DD" or { date: "long" }). - **locale** (string) - Required - The locale string (e.g., "en-US"). ### Response - **Part[]** - An array of part objects containing metadata like `partName`, `token`, `pattern`, and `option`. ``` -------------------------------- ### Parse Dates Source: https://tempo.formkit.com/ Learn how to parse dates from various string formats into JavaScript Date objects. ```APIDOC ## Parse Dates The `parse()` function allows you to convert date strings into JavaScript `Date` objects. It can handle various formats, especially ISO 8601. ### Function Signature ```typescript function parse(dateString: string, format?: string | object): Date ``` ### Example Usage ```javascript import { parse } from "@formkit/tempo" const dateString = "2026-04-19T00:00:00.000Z" const parsedDate = parse(dateString, "full") // Assuming 'full' can also be used for parsing if it matches the string format console.log(parsedDate) // Output: Date object representing April 19, 2026 ``` **Note:** For robust parsing, it's recommended to use ISO 8601 formatted strings or specify the exact format if known. ``` -------------------------------- ### Format Dates with Styles Source: https://tempo.formkit.com/ Use the format function from @formkit/tempo to display dates using predefined styles like 'full', 'long', 'medium', or 'short'. You can also specify a locale for internationalization. ```javascript import { format } from "@formkit/tempo" const date = new Date() // These are the same: format(date, "full") format(date, { date: "full" }) format(date, "long") format(date, "medium") format(date, "short") // With an explicit locale: format(date, "full", "it") ``` -------------------------------- ### Manual Date Destructuring Source: https://tempo.formkit.com/ For advanced control, you can use the `parts` and `parseParts` functions to manually destructure and build `Date` objects. ```APIDOC Need even more control? You can use the `parts` and `parseParts` functions to manually destructure a date string and build a `Date` object yourself. ``` -------------------------------- ### Format Date with Custom Tokens Source: https://tempo.formkit.com/ Utilize format tokens for arbitrary date and time formatting. These tokens are similar to those found in libraries like day.js and automatically respect the specified locale. ```javascript import { format } from "@formkit/tempo" // 👇 Try changing this to "fr" const l = "en" const t = new Date() format(t, "YYYY-MM-DD", l) format(t, "MMM D, YYYY", l) format(t, "MMMM D, YYYY", l) format(t, "DD/MM/YYYY", l) format(t, "hh:mm:ss", l) format(t, "h:mm:ss a", l) format(t, "MMMM D, YYYY h:mm a", l) format(t, "dddd, MMMM D, YYYY", l) format(t, "M/D/YY", l) format(t, "h:mm:ss A", l) format(t, "YYYY-MM-DD HH:mm:ss", l) format(t, "MMM D, YYYY HH:mm", l) format(t, "dddd, MMMM D, YYYY h:mm:ss a", l) format(t, "h:mm A", l) format(t, "YYYY-MM-DDTHH:mm:ssZ", l) format(t, "YY-M-D", l) format(t, "YYYY/MM/DD", l) format(t, "MMM D, YYYY HH:mm:ss", l) format(t, "D MMMM YYYY", l) format(t, "HH:mm", l) format(t, "h:mm a Z", l) format(t, "dddd, MMMM D, YYYY h:mm A", l) format(t, "M/D/YYYY", l) format(t, "hh:mm:ss a Z", l) format(t, "YYYY-MM-DDTHH:mm:ss", l) format(t, "MMM D, YYYY h:mm A", l) format(t, "dddd, MMMM D, YYYY HH:mm:ss", l) format(t, "h:mm:ss A Z", l) format(t, "YY/MM/DD", l) format(t, "YYYY MMMM D", l) format(t, "M-D-YY", l) format(t, "HH:mm:ss.SSS", l) format(t, "YYYY-MM-DDTHH:mm:ss.SSSZ", l) ``` -------------------------------- ### Time Styles Source: https://tempo.formkit.com/ Use predefined time styles by providing an object with a 'time' property to the format() function. This can also be combined with the 'date' property. ```APIDOC ## Time Styles To use a time style format, provide an object as the second argument of the `format()` function with a `time` property. This property can also be used in conjunction with the `date` property. ### Styles and Examples **`full`** - `en`: 7:58:13 PM +00:00 - `de`: 19:58:13 +00:00 - `zh`: +00:00 19:58:13 **`long`** - `en`: 7:58:13 PM +0000 - `de`: 19:58:13 +0000 - `zh`: +0000 19:58:13 **`medium`** - `en`: 7:58:13 PM - `de`: 19:58:13 - `zh`: 19:58:13 **`short`** - `en`: 7:58 PM - `de`: 19:58 - `zh`: 19:58 ### Usage Examples ```javascript import { format } from "@formkit/tempo" const date = "2010-06-09T15:32:00Z" // Using time styles format(date, { time: "full" }) format(date, { time: "long" }) format(date, { time: "medium" }) format(date, { time: "short" }) // Combining date and time styles format(date, { date: "full", time: "short" }) format(date, { date: "medium", time: "long" }) // With an explicit locale format(date, "full", "fr") ``` ``` -------------------------------- ### Format Date with Time Styles Source: https://tempo.formkit.com/ Use the `format` function with an object specifying a `time` property to apply predefined time styles. The `time` property can be combined with a `date` property for combined formatting. ```javascript import { format } from "@formkit/tempo" const date = "2010-06-09T15:32:00Z" format(date, { time: "full" }) format(date, { time: "long" }) format(date, { time: "medium" }) format(date, { time: "short" }) // With a date style format(date, { date: "full", time: "short" }) format(date, { date: "medium", time: "long" }) ``` -------------------------------- ### Comparison Helpers Source: https://tempo.formkit.com/ Boolean comparison functions for dates. ```APIDOC ## isAfter / isBefore ### Description Checks if the first date is chronologically after or before the second date. ### Parameters #### Arguments - **inputDate** (string | Date) - Required - The date to compare. - **dateToCompare** (string | Date) - Required - The reference date. ### Response - **Returns** (boolean) - True if the condition is met, otherwise false. ``` -------------------------------- ### ParseOptions Interface Source: https://tempo.formkit.com/ The `parse` function can accept an object of options for detailed control over parsing. ```APIDOC ### Parsing options The `parse` function can accept an object of options as its argument: ```typescript interface ParseOptions { /** * A string representing a date. */ date: string, /** * The format that should be used to parse the date. * This is a string composed of tokens. */ format: Format, /** * The locale used to parse the date. */ locale: string, /** * A function that can be used to filter out * parts of the format. This is useful when using the format styles * like { date: 'full', time: 'full' } and not wanting to keep * all the parts of the given format. */ partFilter?: (part: Part) => boolean, /** * The behavior to use when a date overflows a given month. * For example, if the date to parse is February 29, 2023 — there is * no 29th day of February. In this case overflow "forward" would * result in March 1, 2023, "backward" would result in * February 28, 2023 and "throw" would throw an error. */ dateOverflow?: "forward" | "backward" | "throw" } ``` ``` -------------------------------- ### Timezone Handling Functions Source: https://tempo.formkit.com/ Functions for creating, formatting, and calculating timezone-aware dates. ```APIDOC ## Timezones ### Key concept A timezone is really an expression or "view" of a given absolute time. An airplane departing Amsterdam `2012-04-07 11:00:00 UTC` leaves the ground at the same moment in every timezone on earth. JavaScript’s `Date` object is "absolute" in the same way as the airplane’s takeoff. A timezone is only a way to express that moment relative the geography and politics of a given region. ## Using timezones ### Creating timezone dates The most basic timezone aware function is `tzDate` which allows you to create a new Date object at in a particular timezone. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { tzDate } from "@formkit/tempo" // Produces the date for 12 noon Nov 18, 2013 in New York tzDate("2013-11-18 12:00", "America/New_York") ``` ### Response #### Success Response (Date Object) - **Date Object**: A JavaScript Date object representing the specified time in the given timezone. #### Response Example ```json { "example": "2013-11-18T17:00:00.000Z" } ``` ### Formatting timezones The `format` function can accept a `tz` option to format a date in a specific timezone. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **date** (Date | string | number) - The date to format. - **format** (string) - The desired output format string. - **tz** (string) - The IANA timezone name (e.g., "America/New_York"). ### Request Example ```javascript import { format } from "@formkit/tempo" const date = new Date() // Time in New York? format({ date, format: "hh:mm a", tz: "America/New_York", }) // Time in Tokyo? format({ date, format: "hh:mm a", tz: "Asia/Tokyo", }) ``` ### Response #### Success Response (string) - **string**: The formatted date string in the specified timezone. #### Response Example ```json { "example": "03:58 pm" } ``` ### Calculating offsets Tempo uses the `Intl.DateTimeFormat` API to extract timezone information, that makes working with timezones as simple as possible. The `offset()` function calculates the amount of offset between any two timezones (given in `+-HH:mm` or `+-HH:mm:ss` for historical timezones with sub-minute precision). Historical timezones (before standardization) had offsets based on local mean time, which could include seconds. For example, America/Detroit in 1904 had an offset of `-05:32:11`. Tempo fully supports these sub-minute offsets in both formatting and parsing. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { offset } from "@formkit/tempo" const date = new Date() // Your browser’s offset to UTC offset(date) // Your browser’s offset to Hawaii offset(date, "Pacific/Honolulu") // Your Hawaii’s offset to UTC offset(date, "UTC", "Pacific/Honolulu") // The offset from London to New York today offset(date, "Europe/London", "America/New_York") // The offset from Moscow to Kolkata, India offset(date, "Europe/Moscow", "Asia/Kolkata") // 👀 Dates matter due to DST: offset("2023-10-25", "Europe/London", "America/New_York") offset("2023-10-30", "Europe/London", "America/New_York") ``` ### Response #### Success Response (string) - **string**: The timezone offset in `+-HH:mm` or `+-HH:mm:ss` format. #### Response Example ```json { "example": "+00:00" } ``` ``` -------------------------------- ### date Source: https://tempo.formkit.com/ Converts an ISO 8601 like string into a Date object. It is a no-operation on existing Date objects. ISO 8601 strings do not need to be complete to be accepted, but you need at least a year and month. ```APIDOC ## date ### Description Converts an ISO 8601 like string into a Date object (noop on `Date` objects). ISO 8601 strings do not need to be complete to be accepted, but you need at least a year and month. ### Method `date` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { date } from "@formkit/tempo" // Partial ISO 8601 strings are acceptable date("2013-11") // Date at UTC date("2013-11-18T12:00:00Z") // Date with an offset (see tzDate() for timezones) date("2013-11-18T12:00:00-0500") ``` ### Response #### Success Response (200) - **Date** (Date) - A Date object created from the input string. #### Response Example ```json { "example": "2013-11-01T00:00:00.000Z" } ``` ``` -------------------------------- ### Date Equality and Comparison Functions Source: https://tempo.formkit.com/ Functions to check if dates are equal or share the same time components. ```APIDOC ## isEqual ### Description Returns true if the first date is equal to the second date, otherwise false. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { isEqual } from "@formkit/tempo" isEqual("2013-03-15", "2013-03-16") isEqual("2013-03-16", "2013-03-16") ``` ### Response #### Success Response (boolean) - **true**: If dates are equal. - **false**: If dates are not equal. #### Response Example ```json { "example": "true" } ``` ## sameMillisecond ### Description Checks if two dates have the same millisecond value (0-999). This compares only the millisecond component, ignoring the rest of the timestamp. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { sameMillisecond } from "@formkit/tempo" const dateA = new Date() const dateB = new Date() sameMillisecond(dateA, dateB) ``` ### Response #### Success Response (boolean) - **true**: If dates share the same millisecond. - **false**: If dates do not share the same millisecond. #### Response Example ```json { "example": "true" } ``` ## sameSecond ### Description Checks if two dates are the same second. This function is useful for comparing dates but ignoring the milliseconds. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { sameSecond } from "@formkit/tempo" const dateA = new Date() const dateB = new Date() sameSecond(dateA, dateB) ``` ### Response #### Success Response (boolean) - **true**: If dates share the same second. - **false**: If dates do not share the same second. #### Response Example ```json { "example": "true" } ``` ## sameMinute ### Description Checks if two dates are the same minute. This function is useful for comparing dates but ignoring the seconds and milliseconds. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { sameMinute } from "@formkit/tempo" const dateA = new Date() const dateB = new Date() sameMinute(dateA, dateB) ``` ### Response #### Success Response (boolean) - **true**: If dates share the same minute. - **false**: If dates do not share the same minute. #### Response Example ```json { "example": "true" } ``` ## sameHour ### Description Checks if two dates are the same hour. This function is useful for comparing dates but ignoring the minutes, seconds, and milliseconds. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { sameHour } from "@formkit/tempo" const dateA = new Date() const dateB = new Date() sameHour(dateA, dateB) ``` ### Response #### Success Response (boolean) - **true**: If dates share the same hour. - **false**: If dates do not share the same hour. #### Response Example ```json { "example": "true" } ``` ## sameDay ### Description Checks if two dates are the same day. This function is useful for comparing dates but ignoring the time. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { sameDay } from "@formkit/tempo" const dateA = new Date() const dateB = new Date() sameDay(dateA, dateB) ``` ### Response #### Success Response (boolean) - **true**: If dates share the same day. - **false**: If dates do not share the same day. #### Response Example ```json { "example": "true" } ``` ## sameYear ### Description Checks if two dates are the same year. This function is useful for comparing dates but ignoring the month, day, and time. ### Method N/A (Function Signature) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { sameYear } from "@formkit/tempo" const dateA = new Date() const dateB = new Date() sameYear(dateA, dateB) ``` ### Response #### Success Response (boolean) - **true**: If dates share the same year. - **false**: If dates do not share the same year. #### Response Example ```json { "example": "true" } ``` ``` -------------------------------- ### Timezones Source: https://tempo.formkit.com/ Details on how Tempo handles timezones and timezone-related manipulations. ```APIDOC ## Timezones Tempo allows you to work with timezones, enabling manipulation and formatting of dates across different time regions. The library aims to be concise, with timezone utilities adding minimal code size. Tempo mines JavaScript's `Intl.DateTimeFormat` to extract complex data like timezone offsets and locale-aware date formats, providing a simple API for timezone-related operations. **Key Points:** * Tempo functions generally operate in the local timezone unless otherwise specified. * The library extracts timezone information using native browser APIs. **Example (Conceptual):** ```javascript // Conceptual example - actual functions may vary import { formatInTimezone } from "@formkit/tempo" const date = new Date('2023-10-27T10:00:00Z') // UTC time const formattedInNY = formatInTimezone(date, 'America/New_York', 'full') console.log(formattedInNY) // e.g., "Friday, October 27, 2023" ``` For detailed information on specific timezone functions and their usage, please consult the official Tempo documentation. ``` -------------------------------- ### dayEnd Source: https://tempo.formkit.com/ Returns a new Date object with the time set to 23:59:59.999 (local time). ```APIDOC ## dayEnd ### Description Returns a new Date object with the time set to 23:59:59.999 (local time). ### Method `dayEnd` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { dayEnd } from "@formkit/tempo" dayEnd("2023-10-26T10:30:00Z") ``` ### Response #### Success Response (200) - **Date** (Date) - A new Date object representing the end of the day. #### Response Example ```json { "example": "2023-10-26T23:59:59.999Z" } ``` ``` -------------------------------- ### Difference Helpers Source: https://tempo.formkit.com/ Functions to calculate the difference between two dates in various units. ```APIDOC ## diff[Unit] ### Description Calculates the difference between two dates in milliseconds, seconds, minutes, hours, days, weeks, months, or years. ### Parameters #### Arguments - **dateA** (string | Date) - Required - The first date. - **dateB** (string | Date) - Required - The second date. - **roundingMethod** ("trunc" | "round" | "floor" | "ceil") - Optional - The method used for rounding partial units (not applicable to diffMilliseconds). ### Response - **Returns** (number) - The calculated difference. ``` -------------------------------- ### Generate date format parts Source: https://tempo.formkit.com/ Produces an array of parts from a format string or object, similar to Intl.DateTimeFormat.formatToParts(). ```typescript import { parts } from "@formkit/tempo" parts("hh:mm a", "en") parts({ date: "long" }, "en") ``` -------------------------------- ### addMinute Source: https://tempo.formkit.com/ Returns a new Date object with a positive or negative number of minutes applied to the date argument. To subtract minutes, use a negative number. ```APIDOC ## addMinute ### Description Returns a new Date object with a positive or negative number of minutes applied to the date argument. To subtract minutes, use a negative number. ### Method `addMinute` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { addMinute } from "@formkit/tempo" // Add 30 minutes addMinute("2023-10-26T10:00:00Z", 30) // Subtract 15 minutes addMinute("2023-10-26T10:00:00Z", -15) ``` ### Response #### Success Response (200) - **Date** (Date) - A new Date object with the modified date. #### Response Example ```json { "example": "2023-10-26T10:30:00.000Z" } ``` ``` -------------------------------- ### hourEnd Source: https://tempo.formkit.com/ Returns a new Date object with the minutes part of the time set to 59:59.999 (local time). ```APIDOC ## hourEnd ### Description Returns a new Date object with the minutes part of the time set to 59:59.999 (local time). ### Method `hourEnd` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { hourEnd } from "@formkit/tempo" hourEnd("2023-10-26T10:30:00Z") ``` ### Response #### Success Response (200) - **Date** (Date) - A new Date object representing the end of the hour. #### Response Example ```json { "example": "2023-10-26T10:59:59.999Z" } ``` ``` -------------------------------- ### Function: parseParts Source: https://tempo.formkit.com/ Parses a date string into an array of parts with extracted values based on a provided parts configuration. ```APIDOC ## parseParts ### Description Given a date string and an array of parts (generated by the `parts` function), this function returns the parts with the appropriate values extracted from the date string and added to a `value` property. ### Parameters - **dateString** (string) - Required - The date string to parse (e.g., "2021-01-01"). - **parts** (Part[]) - Required - An array of part objects defining the structure to parse against. ### Response - **FilledPart[]** - An array of parts containing the original configuration plus the extracted `value` string. ``` -------------------------------- ### yearDays Source: https://tempo.formkit.com/ Returns the number of days in a given year. ```APIDOC ## yearDays ### Description Returns the number of days in a given year, accounting for leap years and century years. ### Parameters #### Arguments - **date** (Date) - Required - The date object to extract the year from. ### Response - **Returns** (number) - The total number of days in the year. ``` -------------------------------- ### Convert String to Date Object with Tempo Source: https://tempo.formkit.com/ The `date` function converts ISO 8601-like strings into Date objects. It accepts partial strings and handles UTC or offset dates. ```javascript import { date } from "@formkit/tempo" // Partial ISO 8601 strings are acceptable date("2013-11") // Date at UTC date("2013-11-18T12:00:00Z") // Date with an offset (see tzDate() for timezones) date("2013-11-18T12:00:00-0500") ``` -------------------------------- ### Format and Parse Milliseconds with SSS Source: https://tempo.formkit.com/ Use the 'SSS' token to format milliseconds to 3 digits. When parsing, 'SSS' accepts variable-length fractional seconds (1-9 digits). ```javascript import { format, parse } from "@formkit/tempo" // Format with milliseconds using SSS token const d = new Date("2024-01-15T10:30:45.789Z") format({ date: d, format: "HH:mm:ss.SSS", tz: "UTC" }) format({ date: d, format: "YYYY-MM-DDTHH:mm:ss.SSSZ", tz: "UTC" }) // SSS always outputs 3 digits, padding with zeros const d2 = new Date("2024-01-15T10:30:45.007Z") format({ date: d2, format: "ss.SSS", tz: "UTC" }) // Parse milliseconds - SSS accepts variable-length input parse("10:30:45.789", "HH:mm:ss.SSS") // 1 digit -> 700ms parse("10:30:45.7", "HH:mm:ss.SSS") // 2 digits -> 780ms parse("10:30:45.78", "HH:mm:ss.SSS") // 6 digits -> 123ms (truncates to ms) parse("10:30:45.123456", "HH:mm:ss.SSS") ``` -------------------------------- ### Format Date with Explicit Locale Source: https://tempo.formkit.com/ Specify a locale as the third argument to the `format` function to control the language of the output. This is useful for internationalization. ```javascript import { format } from "@formkit/tempo" const date = "2010-06-09T15:32:00Z" // With an explicit locale: format(date, { date: "full", time: "short" }, "fr") ``` -------------------------------- ### Add Days to a Date with Tempo Source: https://tempo.formkit.com/ Use `addDay` to add a positive or negative number of days to a date. Accepts ISO 8601 strings or Date objects. ```javascript import { addDay } from "@formkit/tempo" // Add 1 day addDay("2013-03-15") // Add 5 days addDay("2013-03-15", 5) // Subtract 3 days addDay("2013-03-15", -3) ``` -------------------------------- ### Calculate timezone offsets with offset Source: https://tempo.formkit.com/ Computes the difference between two timezones, supporting historical sub-minute offsets. ```typescript import { offset } from "@formkit/tempo" const date = new Date() // Your browser’s offset to UTC offset(date) // Your browser’s offset to Hawaii offset(date, "Pacific/Honolulu") // Your Hawaii’s offset to UTC offset(date, "UTC", "Pacific/Honolulu") // The offset from London to New York today offset(date, "Europe/London", "America/New_York") // The offset from Moscow to Kolkata, India offset(date, "Europe/Moscow", "Asia/Kolkata") // 👀 Dates matter due to DST: offset("2023-10-25", "Europe/London", "America/New_York") offset("2023-10-30", "Europe/London", "America/New_York") ``` -------------------------------- ### addDay Source: https://tempo.formkit.com/ Returns a new Date object with a positive or negative number of days applied to the date argument. To subtract days, use a negative number. ```APIDOC ## addDay ### Description Returns a new Date object with a positive or negative number of days applied to the date argument. To subtract days, use a negative number. ### Method `addDay` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { addDay } from "@formkit/tempo" // Add 1 day addDay("2013-03-15") // Add 5 days addDay("2013-03-15", 5) // Subtract 3 days addDay("2013-03-15", -3) ``` ### Response #### Success Response (200) - **Date** (Date) - A new Date object with the modified date. #### Response Example ```json { "example": "2013-03-16T00:00:00.000Z" } ``` ``` -------------------------------- ### Parse Date String with Format and Locale Source: https://tempo.formkit.com/ Use the `parse` function to convert a date string into a `Date` object. ISO 8601 is the default format. Specify format and locale for non-standard strings. ```javascript import { parse, format } from "@formkit/tempo" // ISO 8601 is the default format parse("1987-12-17") // Sample date formats parse("March 7, 1999", "MMMM D, YYYY", "en-US") parse("12/17/1929", "MM/DD/YYYY") parse("09-11-2049", "DD-MM-YYYY") parse("Feb 11, 2011", "MMM D, YYYY") parse("5 September 1987", "D MMMM YYYY") parse("1982-05-17T07:44:00+0000", "YYYY-MM-DDTHH:mm:ssZ") parse("23/08/1994 07:44 PM", "DD/MM/YYYY hh:mm A") parse("1964-01-12 19:44:00", "YYYY-MM-DD HH:mm:ss") parse("04/27/1942 07:44:00 PM", "MM/DD/YYYY hh:mm:ss A") // Parse only time parse("07:44", "HH:mm") // Time parsed as utc parse("07:44 -0000", "HH:mm ZZ") ``` -------------------------------- ### Modify Dates Source: https://tempo.formkit.com/ Information on how to manipulate and change date values using Tempo. ```APIDOC ## Modify Dates Tempo provides utilities to manipulate and change date values. Specific functions for modification are detailed in the library's documentation. **Example (Conceptual):** While the provided text doesn't detail specific modification functions, conceptually, you might expect functions like `addDays`, `subtractMonths`, `setHours`, etc. ```javascript // Conceptual example - actual functions may vary import { addDays } from "@formkit/tempo" const today = new Date() const tomorrow = addDays(today, 1) console.log(tomorrow) ``` Refer to the official Tempo documentation for a complete list of date manipulation functions. ```