1.4.0 • Published 6 months ago
@janiscommerce/app-dates v1.4.0
@janiscommerce app-dates
This package provides dates module for use in Janis apps.
📦 Installation
npm install @janiscommerce/app-datesThe idea behind this package is to standardize the delivery date format for the different apps.
Examples
| Delivery date | Result |
|---|---|
| 2024-10-15T22:50:03.553Z | Until Oct 15, 19:50 hs |
| 2024-10-18T22:50:03.553Z | Until today, 19:50 hs |
| 2024-10-19T22:50:03.553Z | Until tomorrow, 19:50 hs |
| 2024-10-18T20:50:03.553Z', '2024-10-18T22:50:03.553Z' | today, 17:50 - 19:50 hs |
| 2024-10-19T20:50:03.553Z' , '2024-10-19T22:50:03.553Z' | Tomorrow, 17:50 - 19:50 hs |
| 2024-10-20T22:50:03.553Z' , '2024-10-20T23:50:03.553Z | Oct 20, 19:50 - 20:50 hs |
| 2024-10-20T22:50:03.553Z' , '2025-10-21T23:50:03.553Z | Oct 20 2024, 19:50 - Oct 21 2025, 20:50 hs |
| 2024-10-20T22:50:03.553Z', '2024-10-21T22:50:03.553Z' | Oct 20, 19:50 - Oct 21, 19:50 hs |
Module
DateHandler
Kind: global class
- DateHandler
- new DateHandler(config)
- .isValid(date) ⇒ boolean
- .setLanguage(lang) ⇒ void
- .formatDelivery(date) ⇒ string | null
- .format(date, format, options) ⇒
new DateHandler(config)
| Param | Type | Default | Description |
|---|---|---|---|
| config | Object | ||
| config.locale | "en" | "es" | "pt-BR" | "pt" | en | config.locale |
Example
const Dates = new DateHandler({ locale: 'es' });
const Dates = new DateHandler(); // default locale 'en'dateHandler.isValid(date) ⇒ boolean
Kind: instance method of DateHandler
| Param | Type |
|---|---|
| date | Date |
Example
const Dates = new DateHandler({ locale: 'es' });
Dates.isValid('2024-10-04T21:26:33.801Z'); // true
Dates.isValid('Janis commerce'); // falsedateHandler.setLanguage(lang) ⇒ void
Kind: instance method of DateHandler
| Param | Type |
|---|---|
| lang | string |
Example
const Dates = new DateHandler({ locale: 'es' });
Dates.setLanguage('en');dateHandler.formatDelivery(date) ⇒ string | null
Kind: instance method of DateHandler
| Param | Type | Description |
|---|---|---|
| date | Date | Array.<Date> | For more information, see formats |
Example
const Dates = new DateHandler({locale: 'es'})
Dates.formatDeliveryDate('2024-10-04T21:26:33.801Z') // 10/04/2024
Dates.formatDeliveryDate(['2024-10-20T22:50:03.553Z', '2024-10-21T22:50:03.553Z']), // 10/20 19:50 - 10/21 19:50dateHandler.format(date, format, options) ⇒
Kind: instance method of DateHandler
Returns: The format function will return the result of the formatSingleDate function called with
the provided date, format, and options. If the date argument is not a valid Date, an error
message will be logged using logError and null will be returned.
| Param | Type | Description |
|---|---|---|
| date | Date | The date parameter is the date that you want to format. It should be a valid Date object. |
| format | string | The format parameter in the format function is used to specify the format in which the date should be displayed. It could be a string containing a combination of date and time format tokens, such as 'YYYY-MM-DD HH:mm:ss'. This format string defines how the date should be formatted For more information, see formats |
| options | Options is an object that can contain additional configuration settings for formatting the date. These settings can include things like specifying the time zone, customizing the output format, or providing any other specific requirements for formatting the date. locale inherits it from the instance of class For more information, see options |
Example
const Dates = new DateHandler({ locale: 'es' });
Dates.format('2024-10-04T21:26:33.801Z', ''); // 10/04/2024