DateTime
DateTime
The DateTime module is responsible for performing date handling actions. Its methods can be accessed as in the example below:
const date = await DateTime.addDate["v1_0_0"]({
unit: 'd',
})
Methods
addDate
Method responsible for adding a time unit to a date.
const date = await DateTime.addDate["v1_0_0"]({
unit: 'd',
})
Required parameters
unit: String - expects a string with the time unit that will be added. The possible values are:y: year;M: month;d: day;w: week;h: hour;m: minute;s: second;ms: millisecond.
Optional parameters
date: String - expects a string with the date that will be manipulated. If it is not provided, the current date is used.configuration: Object - expects an object with the date settings. These settings must be obtained through the configurations method.inputFormat: String - expects a string with the format of the date that will be manipulated. If it is not provided, the default American format (YYYY-MM-DD) is used.outputFormat: String - expects a string with the format of the date that will be returned. If it is not provided, the default American format (YYYY-MM-DD) is used.outputLocale: String - expects a string with the language of the date that will be returned. If it is not provided, the default language is used. The languages available are:pt-branden.quantity: Number - expects a number with the amount of time units that will be added. If it is not provided, the value 1 is used.
Return
The constant or variable created, such as the date of the example shown earlier, receives a string with the new date manipulated.
calculateDateDifference
Method responsible for calculating the difference between two dates.
const date = await DateTime.calculateDateDifference["v1_0_0"]({
startDate: '2020-01-01',
endDate: '2020-01-02',
unit: 'd',
})
Required parameters
startDate: String - expects a string with the initial date.endDate: String - expects a string with the final date.unit: String - expects a string with the time unit that will be returned. The possible values are:y: year;M: month;d: day;w: week;h: hour;m: minute;s: second;ms: millisecond.
Optional parameters
inputStartDateFormat: String - expects a string with the format of the initial date that will be manipulated. If it is not provided, the default American format (YYYY-MM-DD) is used.inputEndDateFormat: String - expects a string with the format of the final date that will be manipulated. If it is not provided, the default American format (YYYY-MM-DD) is used.
Return
The constant or variable created, such as the date of the example shown earlier, receives a number representing the difference calculated between the two dates in the unit specified.
checkHoliday
Method responsible for checking whether a date is a holiday.
const isHoliday = await DateTime.checkHoliday["v1_0_0"]({
configurations: configurations,
})
Required parameters
configurations: Object - expects an object with the holiday settings. These settings must be obtained through the configurations method.
Optional parameters
date: String - expects a string with the date that will be checked. If it is not provided, the current date is used.inputFormat: String - expects a string with the format of the date that will be manipulated. If it is not provided, the default format (DD/MM/YYYY) is used.
Return
The constant or variable created, such as the date of the example shown earlier, receives a boolean value, which is true if the date is a holiday and false otherwise.
configurations
Method responsible for creating a holiday configuration for the days of the year.
const configurations = await DateTime.configurations["v1_0_0"]({
holidays: {
holidayPathFile: 'C:/Users/Roberty/Desktop/feriados.csv',
delimiter: ';',
format: 'DD/MM/YYYY',
},
weekdayHolidays: ['SATURDAY', 'SUNDAY']
})
Required parameters
This method has no required parameters.
Optional parameters
holidays: Object - expects an object with the holiday information. It can be provided in two ways:- By file:
{ holidayPathFile: String, delimiter: String, format: String }— loads the holidays from a CSV file.holidayPathFile: String - path of the CSV file with the holiday dates.delimiter: String - delimiter of the CSV columns. Default value:;.format: String - format of the dates in the file. Default value:DD/MM/YYYY.
- By list:
{ holidayList: String[], delimiter: String, format: String }— provides the holidays directly as an array of strings.holidayList: String[] - array with the holiday dates.delimiter: String - delimiter. Default value:;.format: String - format of the dates. Default value:DD/MM/YYYY.
- By file:
weekdayHolidays: Array - expects an array with the days of the week that will be considered holidays. The possible values are:SATURDAY,SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY.
Return
The constant or variable created, such as the configurations of the example shown earlier, receives an object with the settings created. This object gives access to the following properties:
configurations.holidays: Object - returns an object with the following properties:days: Object - returns an object with the following properties:format: String - returns a string with the date format.list: Array - returns an array with the days of the week that will be considered holidays.
weekDays: Array - returns an array with the days of the week that will be considered holidays.
formatDate
Method responsible for formatting a date.
const formattedDate = await DateTime.formatDate["v1_0_0"]({
date: "2020-01-01",
inputFormat: "yyyy-mm-dd",
outputFormat: "yyyy-mm-dd"
})
Required parameters
This method has no required parameters.
Optional parameters
date: String - expects a string with the date that will be formatted. If it is not provided, the current date is used.inputFormat: String - expects a string with the format of the date that will be manipulated. If it is not provided, the default American format (YYYY-MM-DD) is used.outputFormat: String - expects a string with the format of the date that will be manipulated. If it is not provided, the default American format (YYYY-MM-DD) is used.outputLocale: String - expects a string with the language of the date that will be returned. If it is not provided, the default language is used. The languages available are:pt-branden.
Return
The constant or variable created, such as the formattedDate of the example shown earlier, receives a string with the date formatted.
getDateInformation
Method responsible for getting information of a date.
const dateInformation = await DateTime.getDateInformation["v1_0_0"]({
date: "2020-01-01",
inputFormat: "yyyy-mm-dd",
})
Required parameters
This method has no required parameters.
Optional parameters
date: String - expects a string with the date that will be formatted. If it is not provided, the current date is used.inputFormat: String - expects a string with the format of the date that will be manipulated. If it is not provided, the default American format (YYYY-MM-DD) is used.locale: String - expects a string with the language of the date that will be returned. If it is not provided, the default language is used. The languages available are:pt-branden.configurations: Object - expects an object with the date settings. These settings must be obtained through the configurations method.
Return
The constant or variable created, such as the dateInformation of the example shown earlier, receives an object with the date information. This object gives access to the following properties:
dateInformation.day: Number - returns the day number of the date.dateInformation.dayName: String - returns the name of the day of the week of the date.dateInformation.firstDateOfTheMonth: String - returns a string with the date of the first day of the month.dateInformation.lastDateOfTheMonth: String - returns a string with the date of the last day of the month.dateInformation.firstDateOfTheWeek: String - returns a string with the date of the first day of the week.dateInformation.lastDateOfTheWeek: String - returns a string with the date of the last day of the week.dateInformation.firstWorkingDayOfTheMonth: Number - returns the day number of the first working day of the month.dateInformation.lastWorkingDayOfTheMonth: Number - returns the day number of the last working day of the month.dateInformation.month: Number - returns the month number of the date.dateInformation.monthName: String - returns the name of the month of the date.dateInformation.year: Number - returns the year number of the date.
removeDate
Method responsible for removing a time unit from a date.
const date = await DateTime.removeDate["v1_0_0"]({
date: "2020-01-01",
inputFormat: "yyyy-mm-dd",
unit: "day",
value: 1
})
Required parameters
unit: String - expects a string with the time unit that will be removed. The possible values are:y: year;M: month;d: day;w: week;h: hour;m: minute;s: second;ms: millisecond.
Optional parameters
date: String - expects a string with the date that will be formatted. If it is not provided, the current date is used.inputFormat: String - expects a string with the format of the date that will be manipulated. If it is not provided, the default American format (YYYY-MM-DD) is used.outputFormat: String - expects a string with the format of the date that will be manipulated. If it is not provided, the default American format (YYYY-MM-DD) is used.outputLocale: String - expects a string with the language of the date that will be returned. If it is not provided, the default language is used. The languages available are:pt-branden.configurations: Object - expects an object with the date settings. These settings must be obtained through the configurations method.quantity: Number - expects a number with the amount of time units that will be removed.
Return
The constant or variable created, such as the date of the example shown earlier, receives a string with the date subtracted.