1.4.0 • Published 6 months ago

@janiscommerce/app-dates v1.4.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

@janiscommerce app-dates

Build Status Coverage Status npm version

This package provides dates module for use in Janis apps.

📦 Installation

npm install @janiscommerce/app-dates

The idea behind this package is to standardize the delivery date format for the different apps.

Examples

Delivery dateResult
2024-10-15T22:50:03.553ZUntil Oct 15, 19:50 hs
2024-10-18T22:50:03.553ZUntil today, 19:50 hs
2024-10-19T22:50:03.553ZUntil 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.553ZOct 20, 19:50 - 20:50 hs
2024-10-20T22:50:03.553Z' , '2025-10-21T23:50:03.553ZOct 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

new DateHandler(config)

ParamTypeDefaultDescription
configObject
config.locale"en" | "es" | "pt-BR" | "pt"enconfig.locale

Example

const Dates = new DateHandler({ locale: 'es' });
const Dates = new DateHandler(); // default locale 'en'

dateHandler.isValid(date) ⇒ boolean

Kind: instance method of DateHandler

ParamType
dateDate

Example

const Dates = new DateHandler({ locale: 'es' });
Dates.isValid('2024-10-04T21:26:33.801Z'); // true
Dates.isValid('Janis commerce'); // false

dateHandler.setLanguage(lang) ⇒ void

Kind: instance method of DateHandler

ParamType
langstring

Example

const Dates = new DateHandler({ locale: 'es' });
Dates.setLanguage('en');

dateHandler.formatDelivery(date) ⇒ string | null

Kind: instance method of DateHandler

ParamTypeDescription
dateDate | 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

dateHandler.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.

ParamTypeDescription
dateDateThe date parameter is the date that you want to format. It should be a valid Date object.
formatstringThe 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
optionsOptions 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
1.4.0

6 months ago

1.3.0

9 months ago

1.2.0

9 months ago

1.1.0

10 months ago

1.0.2

10 months ago