Skip to content

janis-commerce/app-dates

Repository files navigation

@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 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

new DateHandler(config)

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'

dateHandler.isValid(date) ⇒ boolean

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

dateHandler.setLanguage(lang) ⇒ void

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');

dateHandler.formatDelivery(date) ⇒ string | null

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

dateHandler.format(date, format, options) ⇒

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published