This package provides dates module for use in Janis apps.
npm install @janiscommerce/app-dates
The idea behind this package is to standardize the delivery date format for the different apps.
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 |
Kind: global class
- DateHandler
- new DateHandler(config)
- .isValid(date) ⇒
boolean
- .setLanguage(lang) ⇒
void
- .formatDelivery(date) ⇒
string
|null
- .format(date, format, options) ⇒
Creates an instance of DateHandler.
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'
Return true or false if date is Valid
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'); // false
Set language if need to be change
Kind: instance method of DateHandler
Param | Type |
---|---|
lang | string |
Example
const Dates = new DateHandler({ locale: 'es' });
Dates.setLanguage('en');
Formate delivery date
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:50
The format
function takes a date, format string, and options, validates the date, and then formats
the date using the specified format and options, logging any errors and returning null if the date
is invalid.
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 |
format | string |
The
|
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.
|
Example
const Dates = new DateHandler({ locale: 'es' });
Dates.format('2024-10-04T21:26:33.801Z', ''); // 10/04/2024