"use strict";
/***************************************************
* Licensed Materials - Property of HCL.
* (c)Copyright HCL America, Inc. 2023-2024
****************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
exports.accessed = exports.zone = exports.yesterday = exports.tomorrow = exports.timeZoneToText = exports.timeToTextInZone = exports.timeMerge = exports.textToTime = exports.modified = exports.locale = exports.getCurrentTimeZone = exports.created = exports.businessDays = exports.adjust = exports.yearFrac = exports.workDayIntl = exports.workDay = exports.weekNum = exports.timeValue = exports.netWorkDaysIntl = exports.netWorkDays = exports.isoWeekNum = exports.interval = exports.eoMonth = exports.eDate = exports.days360 = exports.days = exports.dateValue = exports.dateDif = exports.year = exports.weekday = exports.today = exports.time = exports.second = exports.now = exports.month = exports.minute = exports.hour = exports.day = exports.date = exports._notes_vmx = exports._notes = exports._openFormula = void 0;
const tslib_1 = require("tslib");
/**
* @file Date & Time
* @module date-time
* @category Date & Time
*/
const openf = tslib_1.__importStar(require("../openformula/date-time"));
exports._openFormula = openf;
const openf_compat = tslib_1.__importStar(require("../openformula/compatibility"));
const notesf_base = tslib_1.__importStar(require("../notes/date-time"));
const notesf_vmx = tslib_1.__importStar(require("../notes/voltmx/date-time"));
const notesf = () => API.isCurrentFrameworkVoltMX() ? notesf_vmx : notesf_base;
exports._notes = notesf_base;
exports._notes_vmx = notesf_vmx;
const TIME_SEPARATOR = ':';
const API = tslib_1.__importStar(require("../rosetta/API"));
const common_1 = require("../utils/common");
const error = tslib_1.__importStar(require("../utils/error"));
//-----------------------------
// Rosetta date-time - common functions (exist in both OpenFormula and Notes Formula)
/**
* Constructs the date from year, month, and day of month or translates numbers for the various components of time and date,
* then returns the Date value.
*
* @param {DateOrDateList} yearOrDateTime The year that you want to appear in the resulting date.
* You must specify an entire four-digit year. (For example, use 1996, not 96).
* Or Time-date or Date list. For a Date value such as @Now or [10/31/93 12:00:00], @Date removes the time portion of the value, leaving only the date.
* @param {number} [month] Optional (when DateTime provided). The month that you want to appear in the resulting date. (For example, use 1 to specify January).
* @param {number} [day] Optional (when DateTime provided). The day that you want to appear in the resulting date.
* @param {number} [hour] Optional. The number of hours. This value will be truncated from the resulting date.
* @param {number} [minute] Optional. The number of minutes. This value will be truncated from the resulting date.
* @param {number} [second] Optional. The number of seconds. This value will be truncated from the resulting date.
* @returns {string} A string representation of the date and time of the given year, month and day
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#DATE | www.oasis-open.org}
* @example
* rosettajs.DateTime.date(12, 12, 12); // returns Thu Dec 12 1912 00:00:00 GMT-0500 (Eastern Standard Time)
*/
function date(yearOrDateTime, month, day, //NOSONAR
hour, minute, second) {
var _a;
// Check for no year value - returns current date and time
if (!yearOrDateTime) {
return new Date().toLocaleDateString();
}
// Check for error values
if (yearOrDateTime instanceof Error || month instanceof Error || day instanceof Error) {
return (_a = (0, common_1.anyError)(yearOrDateTime, month, day)) !== null && _a !== void 0 ? _a : error.value;
}
// Open formula does not accept array of Dates as input, so handle it here
if (API.isCurrentAPIOpenFormula()) {
if (Array.isArray(yearOrDateTime) || typeof yearOrDateTime === 'string' || yearOrDateTime instanceof Date) {
let dates = Array.isArray(yearOrDateTime) ? yearOrDateTime : [yearOrDateTime];
const rtnDates = [];
for (const element of dates) {
let result = null;
let d = element;
if (d instanceof Date) {
result = d;
}
else if (typeof d === 'string') {
result = new Date(d);
}
else if (typeof d === 'number') {
result = new Date(d);
}
if (!result || d instanceof Error || result instanceof Error || result.toString() === "Invalid Date") {
result = error.value;
}
rtnDates.push(result);
}
return rtnDates.length === 1 ? rtnDates[0] : rtnDates;
}
// If yearOrDateTime is a number then it is treated as a year rather then an epoch time value
else if (typeof yearOrDateTime === 'number' && typeof month === 'number' && typeof day === 'number') {
return openf.DATE(yearOrDateTime, month, day);
}
else {
return error.value;
}
}
else {
return notesf().date(yearOrDateTime, month, day, hour, minute, second);
}
}
exports.date = date;
/**
* Extracts the day of the month from the specified date.
*
* @param {DateOrDateList} dateOrDateList The date, as a string, number, Date object, or Array of Date objects, containing the day value that you want to extract.
* @returns {NumberOrNumberList} Number or Number list. The number corresponding to the day of the month indicated by dateOrDateList.
* Returns -1 if the Date provided contains only a time value and not a date.
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#DAY | www.oasis-open.org}
* @example
* rosettajs.DateTime.day(2958465); // returns 31 (open formula only)
* @example
* rosettajs.DateTime.day(new Date(1900, 0, 1)); // returns 1
*/
function day(dateOrDateList) {
var _a;
if (dateOrDateList instanceof Error) {
return (_a = (0, common_1.anyError)(dateOrDateList)) !== null && _a !== void 0 ? _a : error.value;
}
else if (API.isCurrentAPIOpenFormula()) {
// Open Formula does not accept array of Dates as input, so handle it here
let dates = Array.isArray(dateOrDateList) ? dateOrDateList : [dateOrDateList];
const rtnDays = [];
dates.forEach((date) => {
let dt = new Date(date);
if (dt.toString() === "Invalid Date") {
rtnDays.push(-1);
}
else {
let result = openf.DAY(dt);
rtnDays.push(result);
}
});
return rtnDays.length === 1 ? rtnDays[0] : rtnDays;
}
// Notes Formula accepts date or date list only
else {
return notesf().Day(dateOrDateList);
}
}
exports.day = day;
/**
* Extracts the number of the hour (0 through 23) from a specified Date.
*
* @param {DateOrDateList} dateOrDateList The date, as a string, Date object, or Array of Date objects, with the hour that you want to extract.
* @returns {NumberOrNumberList} Number or Number list. Hour portion (or list of hours) of the given date.
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#HOUR | www.oasis-open.org}
* @example
* rosettajs.DateTime.hour("1/1/1900 1:00"); // returns 1
* @example
* rosettajs.DateTime.hour(rosettajs.DateTime.date(95, 11, 20, 8, 58, 12)); // returns 8
*/
function hour(dateOrDateList) {
var _a;
if (dateOrDateList instanceof Error) {
return (_a = (0, common_1.anyError)(dateOrDateList)) !== null && _a !== void 0 ? _a : error.value;
}
else if (API.isCurrentAPIOpenFormula()) {
// Open Formula does not accept array of Dates as input, so handle it here
let dates = Array.isArray(dateOrDateList) ? dateOrDateList : [dateOrDateList];
const rtnHours = [];
dates.forEach((date) => {
let dt = new Date(date);
if (dt.toString() === "Invalid Date" || !date.toString().includes(TIME_SEPARATOR)) {
rtnHours.push(-1);
}
else {
let result = openf.HOUR(dt);
rtnHours.push(result);
}
});
return rtnHours.length === 1 ? rtnHours[0] : rtnHours;
}
// Notes Formula accepts date or date list only
else {
return notesf().Hour(dateOrDateList);
}
}
exports.hour = hour;
/**
* Extracts the number of the minutes from a specified Date.
*
* @param {DateOrDateList} dateOrDateList The date, as a string, Date object, or Array of Date objects, of the minuntes you are trying to find.
* @returns {NumberOrNumberList} Number or Number list. Minutes portion (or list of minutes) of the given date.
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#MINUTE | www.oasis-open.org}
* @example
* rosettajs.DateTime.minute("1/1/1900 1:30"); // returns 30
* @example
* rosettajs.DateTime.minute(rosettajs.DateTime.date(95, 11, 20, 8, 58, 12)); // returns 58
*/
function minute(dateOrDateList) {
var _a;
if (dateOrDateList instanceof Error) {
return (_a = (0, common_1.anyError)(dateOrDateList)) !== null && _a !== void 0 ? _a : error.value;
}
else if (API.isCurrentAPIOpenFormula()) {
// Open Formula does not accept array of Dates as input, so handle it here
let dates = Array.isArray(dateOrDateList) ? dateOrDateList : [dateOrDateList];
const rtnMinutes = [];
dates.forEach((date) => {
let dt = new Date(date);
if (dt.toString() === "Invalid Date" || !date.toString().includes(':')) {
rtnMinutes.push(-1);
}
else {
let result = openf.MINUTE(dt);
rtnMinutes.push(result);
}
});
return rtnMinutes.length === 1 ? rtnMinutes[0] : rtnMinutes;
}
// Notes Formula accepts date or date list only
else {
return notesf().Minute(dateOrDateList);
}
}
exports.minute = minute;
/**
* Extracts the number of the month (1-12) from the specified date.
*
* @param {DateOrDateList} dateOrDateList The date, as a string, Date object, or Array of Date objects of the month you are trying to find.
* @returns {NumberOrNumberList} Number or Number list. Month portion (or list of days) of the date (or list of dates).
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#MONTH | www.oasis-open.org}
* @example
* rosettajs.DateTime.month(2958465); // returns 12 (open formula only)
* @example
* rosettajs.DateTime.month(new Date(1900, 0, 31)); // returns 1
*/
function month(dateOrDateList) {
var _a;
if (dateOrDateList instanceof Error) {
return (_a = (0, common_1.anyError)(dateOrDateList)) !== null && _a !== void 0 ? _a : error.value;
}
else if (API.isCurrentAPIOpenFormula()) {
// Open Formula does not accept array of Dates as input, so handle it here
let dates = Array.isArray(dateOrDateList) ? dateOrDateList : [dateOrDateList];
const rtnMonths = [];
dates.forEach((date) => {
let dt = new Date(date);
if (dt.toString() === "Invalid Date") {
rtnMonths.push(-1);
}
else {
let result = openf.MONTH(dt);
rtnMonths.push(result);
}
});
return rtnMonths.length === 1 ? rtnMonths[0] : rtnMonths;
}
// Notes Formula accepts date or date list only
else {
return notesf().Month(dateOrDateList);
}
}
exports.month = month;
/**
* Returns the string representation of the current date and time.
* The Notes parameters, flags and serverNames, are not implemented in VoltFormula at this time.
*
* @returns {Date} A date representation of the current date and time
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#NOW | www.oasis-open.org}
* @example
* rosettajs.DateTime.now(); // returns Wed Jun 07 2023 12:26:36 GMT-0400 (Eastern Daylight Time)
*/
function now() {
if (arguments.length > 0) {
return error.na;
}
return API.isCurrentAPIOpenFormula() ? openf.NOW() : notesf().Now();
}
exports.now = now;
/**
* Extracts the number of the seconds from a specified Date.
* This function presumes that leap seconds never exist.
*
* @param {DateOrDateList} dateOrDateList The date, as a string, Date object, or Array of Date objects, of the seconds you are trying to find.
* @returns {NumberOrNumberList} Number or Number list. Seconds portion (or list of seconds) of the given date.
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#SECOND | www.oasis-open.org}
* @example
* rosettajs.DateTime.second("1/1/1900"); // returns 0
* @example
* rosettajs.DateTime.second("11/20/95 8:58:59"); // returns 59
* @example
* rosettajs.DateTime.second(rosettajs.DateTime.date(95, 11, 20, 8, 58, 12)); // returns 12
*/
function second(dateOrDateList) {
var _a;
if (dateOrDateList instanceof Error) {
return (_a = (0, common_1.anyError)(dateOrDateList)) !== null && _a !== void 0 ? _a : error.value;
}
else if (API.isCurrentAPIOpenFormula()) {
// Open Formula does not accept array of Dates as input, so handle it here
let dates = Array.isArray(dateOrDateList) ? dateOrDateList : [dateOrDateList];
const rtnSeconds = [];
dates.forEach((date) => {
let dt = new Date(date);
if (dt.toString() === "Invalid Date" || !date.toString().includes(':')) {
rtnSeconds.push(-1);
}
else {
let result = openf.SECOND(dt);
rtnSeconds.push(result);
}
});
return rtnSeconds.length === 1 ? rtnSeconds[0] : rtnSeconds;
}
// Notes Formula accepts date or date list only
else {
return notesf().Second(dateOrDateList);
}
}
exports.second = second;
/**
* Constructs and returns a Date object from one of the following combination of Date parameters:
* ( hour, minute, second ), ( year, month, day, hour, minute, second ),
* or Date object or array of Date objects, as per the notes formula Time function parameters.
*
* @param {*} args Date-time object or list of Dates, 6 Numbers representing the date-time, or 3 Numbers from 0 (zero) to 32767 representing the hour, minute, day.
* Any value greater than 23 will be divided by 24 and the remainder will be treated as the time value.
* @returns {number} A number representing time (as a fraction of a day) or Date-time object of the current time; display usually formatted in current locale.
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#TIME | www.oasis-open.org}
* @example
* rosettajs.DateTime.time(1, 1, 1); // returns 0.04237268518518519 (open formula only)
* @example
* rosettajs.DateTime.time(93, 12, 24, 12, 30, 40); // returns 1993-12-24 12:30:40.000 -0000
* @example
* rosettajs.DateTime.time(rosettajs.DateTime.date(93, 12, 24, 12, 30, 40)); // returns 1993-12-24 12:30:40.000 -0000
*/
function time(...args) {
if (API.isCurrentAPIOpenFormula()) {
if (args.length === 3) {
return openf.TIME(args[0], args[1], args[2]);
}
return error.value;
}
else {
return notesf().Time(...args);
}
}
exports.time = time;
/**
* Returns today's date.
*
* @returns {Date} The date object for the current date and time.
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#TODAY | www.oasis-open.org}
* @example
* rosettajs.DateTime.today(); // returns Wed Jun 07 2023 12:26:36 GMT-0400 (Eastern Daylight Time)
*/
function today() {
return API.isCurrentAPIOpenFormula() ? openf.TODAY() : notesf().Today();
}
exports.today = today;
/**
* Extracts the day of the week from a date; if text, uses current locale to convert to a date.
* Returns a number that identifies the day.
*
* @param {DateOrDateList} dateOrDateList The date
* @param {number} [returnType=1] A number that determines the type of return value. The default is 1.
* - **1** Numbers 1 (Sunday) through 7 (Saturday)
* - **2** Numbers 1 (Monday) through 7 (Sunday)
* - **3** Numbers 0 (Monday) through 6 (Sunday)
* - **11** Numbers 1 (Monday) through 7 (Sunday)
* - **12** Numbers 1 (Tuesday) through 7 (Monday)
* - **13** Numbers 1 (Wednesday) through 7 (Tuesday)
* - **14** Numbers 1 (Thursday) through 7 (Wednesday)
* - **15** Numbers 1 (Friday) through 7 (Thursday)
* - **16** Numbers 1 (Saturday) through 7 (Friday)
* - **17** Numbers 1 (Sunday) through 7 (Saturday)
* @returns {number} The day of the week of a given date as a number from 1 through 7. (default)
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#WEEKDAY | www.oasis-open.org}
* @example
* rosettajs.DateTime.weekday(2958465); // returns 6 (open formula only)
* @example
* rosettajs.DateTime.weekday(rosettajs.DateTime.date(1900, 0, 31)); // returns 4
* @example
* rosettajs.DateTime.weekday([rosettajs.DateTime.date(95, 11, 20, 8, 58, 12), rosettajs.DateTime.date(95, 11, 21, 8, 58, 12)]); // returns [2, 3]
*/
function weekday(dateOrDateList, returnType = 1) {
var _a;
if (dateOrDateList instanceof Error) {
return (_a = (0, common_1.anyError)(dateOrDateList)) !== null && _a !== void 0 ? _a : error.value;
}
else if (API.isCurrentAPIOpenFormula()) {
// Open Formula does not accept array of Dates as input, so handle it here
let dates = Array.isArray(dateOrDateList) ? dateOrDateList : [dateOrDateList];
const rtnDays = [];
dates.forEach((date) => {
let dt = new Date(date);
if (dt.toString() === "Invalid Date") {
rtnDays.push(-1);
}
else {
let result = openf.WEEKDAY(dt, returnType);
rtnDays.push(result);
}
});
return rtnDays.length === 1 ? rtnDays[0] : rtnDays;
}
// Notes Formula accepts date or date list only
else {
return notesf().Weekday(dateOrDateList);
}
}
exports.weekday = weekday;
/**
* Extracts the number of the month from the specified date.
*
* @param {DateOrDateList} dateOrDateList The date, as a string, Date object, or Array of Date objects of the year you are trying to find.
* @returns {NumberOrNumberList} Number or Number list. Year portion (or list of days) of the date (or list of dates).
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#YEAR | www.oasis-open.org}
* @example
* rosettajs.DateTime.year(2958465); // returns 1995 (open formula only)
* @example
* rosettajs.DateTime.year(new Date(1900, 0, 1)); // returns 1900
*/
function year(dateOrDateList) {
var _a;
if (dateOrDateList instanceof Error) {
return (_a = (0, common_1.anyError)(dateOrDateList)) !== null && _a !== void 0 ? _a : error.value;
}
else if (API.isCurrentAPIOpenFormula()) {
// Open Formula does not accept array of Dates as input, so handle it here
let dates = Array.isArray(dateOrDateList) ? dateOrDateList : [dateOrDateList];
const rtnYears = [];
dates.forEach((date) => {
let dt = new Date(date);
if (dt.toString() === "Invalid Date") {
rtnYears.push(-1);
}
else {
let result = openf.YEAR(dt);
rtnYears.push(result);
}
});
return rtnYears.length === 1 ? rtnYears[0] : rtnYears;
}
// Notes Formula accepts date or date list only
else {
return notesf().Year(dateOrDateList);
}
}
exports.year = year;
//-----------------------------
// Open Formula date-time
/**
* Calculates the number of days, months, or years between two dates.
*
* @param {CustomDateType} start_date A date that represents the first, or starting date of a given period.
* @param {CustomDateType} end_date A date that represents the last, or ending, date of the period.
* @param {string} unit The type of information that you want returned, where:
- "Y": The number of complete years in the period.
- "M": The number of complete months in the period.
- "D": The number of days in the period.
- "MD": The difference between the days in start_date and end_date. The months and years of the dates are ignored.
- "YM": The difference between the months in start_date and end_date. The days and years of the dates are ignored
- "YD": The difference between the days of start_date and end_date. The years of the dates are ignored.
* @returns {Number} Days, months, or years between given dates.
* @example
* rosettajs.DateTime.dateDif("1/1/2001", "1/1/2003", "Y"); // returns 2
* @example
* rosettajs.DateTime.dateDif("6/1/2001", "8/15/2002", "D"); // returns 440
*/
function dateDif(start_date, end_date, unit) {
return openf.DATEDIF(start_date, end_date, unit);
}
exports.dateDif = dateDif;
/**
* Returns the string representation of the date and time from given text.
*
* @param {string} date_text Text that represents a date in an OpenFormula date format, or a reference to a value that contains text that represents a date in an OpenFormula date format.
* @returns {Date} A string representation of the date and time of the given date.
* @example
* rosettajs.DateTime.dateValue("1/1/1900"); // returns Mon Jan 01 1900 00:00:00 GMT-0500 (Eastern Standard Time)
*/
function dateValue(date_text) {
return openf.DATEVALUE(date_text);
}
exports.dateValue = dateValue;
/**
* Returns the number of days between two dates.
*
* @param {CustomDateType} endDate A date that represents the last, or ending, date of the period
* @param {CustomDateType} startDate A date that represents the first, or starting date of a given period
* @returns {number} Number of days between two given dates.
* @example
* rosettajs.DateTime.days("1/2/1900", "1/1/1900"); // returns 1
*/
function days(endDate, startDate) {
return openf.DAYS(endDate, startDate);
}
exports.days = days;
/**
* Calculates the number of days between two dates based on a 360-day year.
*
* @param {CustomDateType} endDate A date that represents the last, or ending, date of the period.
* @param {CustomDateType} startDate A date that represents the first, or starting date of a given period.
* @param {string} [method] Optional. A logical value that specifies whether to use the U.S. or European
* method in the calculation. The default is FALSE.
* - **FALSE** U.S. (NASD) method. If the starting date is the last day of a month, it
* becomes equal to the 30th day of the same month. If the ending date is
* the last day of a month and the starting date is earlier than the 30th
* day of a month, the ending date becomes equal to the 1st day of the next
* month; otherwise the ending date becomes equal to the 30th day of the
* same month.
* - **TRUE** European method. Starting dates and ending dates that occur on the 31st
* day of a month become equal to the 30th day of the same month.
* @returns {number} Number of days between two given dates based on a 360-day year.
* @example
* rosettajs.DateTime.days360("1/1/1901", "12/31/1901", true); // returns 359
*/
function days360(startDate, endDate, method = false) {
return openf.DAYS360(startDate, endDate, method);
}
exports.days360 = days360;
/**
* Returns the date and time that is the indicated number of months before or after the start date.
*
* @param {CustomDateType} startDate A date that represents the first, or starting date of a given period.
* @param {number} months The number of months before or after start_date. A positive value for
* months yields a future date; a negative value yields a past date.
* @returns {Date} The date of the given date and number of months.
* @example
* rosettajs.DateTime.eDate(rosettajs.DateTime.date(2011, 1, 23), 1); // returns Sun Feb 23 2011 00:00:00 GMT-0500 (Eastern Standard Time)
*/
function eDate(startDate, months) {
return openf.EDATE(startDate, months);
}
exports.eDate = eDate;
/**
* Returns the string representation of the date and time of the last day of the
* month before or after a specified number of months.
*
* @param {CustomDateType} startDate A date that represents the first, or starting date of a given period.
* @param {number} months Number of months before or after start_date. A positive value for months
* yields a future date; a negative value yields a past date.
* @returns {Date} The date of the given date number of months.
* @example
* rosettajs.DateTime.eoMonth("1/1/2005", 2); // returns Thu Mar 31 2005 00:00:00 GMT-0500 (Eastern Standard Time)
*/
function eoMonth(startDate, months) {
return openf.EOMONTH(startDate, months);
}
exports.eoMonth = eoMonth;
/**
* Calculates the number of years, months, days, hours, minutes and seconds from a specified number of seconds.
*
* @param {number} second Number of seconds.
* @returns {string} A string representing the years, months, days, hours, minutes and seconds based on the given number of seconds.
* @example
* rosettajs.DateTime.interval(10000000); // returns "P3M25DT17H46M40S"
*/
function interval(second) {
return openf.INTERVAL(second);
}
exports.interval = interval;
/**
* Returns the number of the ISO week number of the year for a given date.
*
* @param {CustomDateType} date The date.
* @returns {number} Number of the week in the year of given date.
* @example
* rosettajs.DateTime.isoWeekNum("1/8/1901"); // returns 2
*/
function isoWeekNum(date) {
return openf.ISOWEEKNUM(date);
}
exports.isoWeekNum = isoWeekNum;
/**
* Returns the number of whole workdays between two dates. Working days excludes weekends and any dates identified in holidays.
*
* @param {DateType} startDate A date that represents the first, or starting date of a given period.
* @param {DateType} endDate A date that represents the last, or ending, date of the period.
* @param {DateType|DateType[]} [holidays] An optional range of one or more dates to exclude from the working
* calendar, such as state and federal holidays and floating holidays.
* @returns {number} The number of whole workdays between two dates.
* @example
* rosettajs.DateTime.netWorkDays("2013-12-04", "2013-12-07"); // returns 3
* @example
* rosettajs.DateTime.netWorkDays("12/4/2013", "1/4/2014", "1/1/2014"); // returns 22
*/
function netWorkDays(startDate, endDate, holidays) {
return openf.NETWORKDAYS(startDate, endDate, holidays);
}
exports.netWorkDays = netWorkDays;
/**
* Returns the number of whole workdays between two dates using parameters to indicate which and how many days are weekend days.
*
* @param {CustomDateType} startDate A date that represents the first, or starting date of a given period.
* @param {CustomDateType} endDate A date that represents the last, or ending, date of the period.
* @param {string} [weekend] Indicates the days of the week that are weekend days and are
* not included in the number of whole working days between start_date and end_date.
* Weekend is a weekend number or string that specifies when weekends occur.
* <br><br>
* Weekend *number* values indicate the following weekend days:
* - **1** Saturday, Sunday (Default value)
* - **2** Sunday, Monday
* - **3** Monday, Tuesday
* - **4** Tuesday, Wednesday
* - **5** Wednesday, Thursday
* - **6** Thursday, Friday
* - **7** Friday, Saturday
* - **11** Sunday only
* - **12** Monday only
* - **13** Tuesday only
* - **14** Wednesday only
* - **15** Thursday only
* - **16** Friday only
* - **17** Saturday only
*
* Weekend *string* values are seven characters long and each character in the string
* represents a day of the week, starting with Monday. 1 represents a non-workday
* and 0 represents a workday. Only the characters 1 and 0 are permitted in the
* string. Using 1111111 will always return 0.
*
* For example, 0000011 would result in a weekend that is Saturday and Sunday.
* @param {DateType|DateType[]} [holidays] An optional range of one or more dates to exclude from the working
* calendar, such as state and federal holidays and floating holidays.
* @returns {number} The number of whole workdays between two dates.
* @example
* rosettajs.DateTime.netWorkDaysIntl("12/4/2013", "12/5/2013"); // returns 2
* @example
* rosettajs.DateTime.netWorkDaysIntl("12/8/2013", "12/9/2013", 2); // returns 0
*/
function netWorkDaysIntl(startDate, endDate, weekend, holidays) {
return openf_compat.NETWORKDAYSINTL(startDate, endDate, weekend, holidays);
}
exports.netWorkDaysIntl = netWorkDaysIntl;
/**
* Converts a time in the form of text to a serial number.
*
* @param {string} timeText The time represented by a text string.
* @returns {number} The decimal number of the time represented by a text string. The decimal
* number is a value ranging from 0 (zero) to 0.99988426, representing the times
* from 0:00:00 (12:00:00 AM) to 23:59:59 (11:59:59 P.M.).
* @example
* rosettajs.DateTime.timeValue("1/1/1900 12:00:00"); // returns ~ 0.5
*/
function timeValue(timeText) {
return openf.TIMEVALUE(timeText);
}
exports.timeValue = timeValue;
/**
* Converts a date to a number representing where the week falls numerically with a year.
*
* There are two systems used for this function:
* - **System 1** The week containing January 1 is the first week of the year, and is numbered week 1.
* - **System 2** The week containing the first Thursday of the year is the first week of the year,
* and is numbered as week 1. This system is the methodology specified in ISO 8601,
* which is commonly known as the European week numbering system.
*
* @param {CustomDateType} date A date within the week.
* @param {number} [return_type] Optional. A number that determines on which day the week begins. The default is 1.
* - **1** Sunday, System 1 (Default value)
* - **2** Monday, System 1
* - **11** Monday, System 1
* - **12** Tuesday, System 1
* - **13** Wednesday, System 1
* - **14** Thursday, System 1
* - **15** Friday, System 1
* - **16** Saturday, System 1
* - **17** Sunday, System 1
* - **21** Monday, System 2
* @returns {number} The week number of given date.
* @example
* rosettajs.DateTime.weekNum("2/1/1909", 2); // returns 6
*/
function weekNum(date, returnType = 1) {
return openf.WEEKNUM(date, returnType);
}
exports.weekNum = weekNum;
/**
* Returns the date before or after a specified number of workdays.
*
* @param {CustomDateType} startDate A date that represents the first, or starting date of a given period.
* @param {number} days The number of nonweekend and nonholiday days before or after start_date.
* A positive value for days yields a future date; a negative value yields a past date.
* @param {DateType|DateType[]} [holidays] An optional range of one or more dates to exclude from the working calendar,
* such as state and federal holidays and floating holidays.
* @returns {Date} The date before or after the specified number of workdays.
* @example
* rosettajs.DateTime.workDay("1/1/1900", 1); // returns 1/2/1900
* @example
* rosettajs.DateTime.workDay("1/1/1900", 2, "1/2/1900"); // returns 1/4/1900
*/
function workDay(startDate, days, holidays) {
return openf.WORKDAY(startDate, days, holidays);
}
exports.workDay = workDay;
/**
* Returns the date before or after a specified number of workdays using parameters to indicate which and how many days are weekend days.
*
* @param {CustomDateType} startDate A date that represents the first, or starting date of a given period
* @param {number} days The number of nonweekend and nonholiday days before or after start_date.
* A positive value for days yields a future date; a negative value yields a past date.
* @param {string|number} [weekend] Indicates the days of the week that are weekend days and are not
* considered working days. Weekend is a weekend number or string that specifies
* when weekends occur.
*
* Weekend number values indicate the following weekend days:
* - **1** Saturday, Sunday (Default value)
* - **2** Sunday, Monday
* - **3** Monday, Tuesday
* - **4** Tuesday, Wednesday
* - **5** Wednesday, Thursday
* - **6** Thursday, Friday
* - **7** Friday, Saturday
* - **11** Sunday only
* - **12** Monday only
* - **13** Tuesday only
* - **14** Wednesday only
* - **15** Thursday only
* - **16** Friday only
* - **17** Saturday only
*
* Weekend string values are seven characters long and each character in the string
* represents a day of the week, starting with Monday. 1 represents a non-workday
* and 0 represents a workday. Only the characters 1 and 0 are permitted in the
* string. Using 1111111 will always return 0.
*
* For example, 0000011 would result in a weekend that is Saturday and Sunday.
* @param {DateType|DateType[]} [holidays] An optional set of one or more dates that are to be excluded
* from the working day calendar. Holidays shall be a range of cells that contain
* the dates, or an array constant of the serial values that represent those dates.
* The ordering of dates or serial values in holidays can be arbitrary.
* @returns {Date} The date and time that was calculated before or after the given date.
* @example
* rosettajs.DateTime.workDay.intl("1/1/1905", 1, 2); // returns 1/3/1905
*/
function workDayIntl(startDate, days, weekend, holidays) {
return openf_compat.WORKDAYINTL(startDate, days, weekend, holidays);
}
exports.workDayIntl = workDayIntl;
/**
* Returns the year fraction representing the number of whole days between start_date and end_date.
*
* @param {CustomDateType} startDate A date that represents the first, or starting date of a given period.
* @param {CustomDateType} endDate A date that represents the last, or ending, date of the period.
* @param {number} [basis] The type of day count basis to use:
* - **0** US (NASD) 30/360 (Default value)
* - **1** Actual/actual
* - **2** Actual/360
* - **3** Actual/365
* - **4** European 30/360
* @returns {number} The year fraction of whole days between given dates.
* @example
* rosettajs.DateTime.yearFrac("1/31/1900", "3/31/1900", 0); // returns ~ 0.16666666666666666
* @example
* rosettajs.DateTime.yearFrac("1/1/1904", "1/1/1905", 1); // returns 1
*/
function yearFrac(startDate, endDate, basis = 0) {
return openf.YEARFRAC(startDate, endDate, basis);
}
exports.yearFrac = yearFrac;
//-----------------------------
// Notes @functions date-time
/**
* Adjusts the specified Date value by the number of years, months, days, hours, minutes, and/or seconds you specify.
* The amount of adjustment may be positive or negative.
*
* @param {DateOrDateList} dateOrDateList The Date or list of Dates you want to increment. This should be a single date, not a range.
* @param {number} years The number of years to increment by.
* @param {number} months The number of months to increment by.
* @param {number} days The number of days to increment by.
* @param {number} hours The number of hours to increment by.
* @param {number} minutes The number of minutes to increment by.
* @param {number} seconds The number of seconds to increment by.
* @returns {TextOrTextList} The adjusted date string or list of adjusted date strings.
* @example
* rosettajs.DateTime.adjust(rosettajs.DateTime.date('6/30/95'), 2, 2, 2, 0, 0, 0); // returns '7/30/1995'
*/
function adjust(dateOrDateList, years, months, days, hours, minutes, seconds) {
return notesf().Adjust(dateOrDateList, years, months, days, hours, minutes, seconds);
}
exports.adjust = adjust;
/**
* Returns the number of business days in one or more date ranges. Inclusive of the date ranges, and excluding provided optional weekends and holidays.
*
* @param {DateOrDateList} startDate Date as string or Date type, or list of Dates. The start of each date range.
* @param {DateOrDateList} endDate Date as string or Date type, or list of Dates. The end of each date range.
* @param {NumberOrNumberList} [daysToExclude] Numer or number list. Optional. Days of the week not counted as business days, where 1 is Sunday and 7 is Saturday.
* Decimal numbers are rounded to integers. Numbers other than 1-7 are ignored. (AKA Weekends)
* @param {string|string[]|Date|Date[]} [datesToExclude] Date as string or Date type, or list of Dates. Optional. Dates not counted as business days. (AKA Holidays)
* @returns {NumberOrNumberList} The number of days from startDates to endDates, inclusive, less daysToExclude and datesToExclude that fall within the date range.
* @example
* rosettajs.DateTime.businessDays("01/01/2001", "12/31/2001", [1, 7], HOLIDAYS); // returns 251, where HOLIDAYS include a list of 10 major US holidays in 2001
*/
function businessDays(startDate, endDate, daysToExclude, datesToExclude) {
return notesf().BusinessDays(startDate, endDate, daysToExclude, datesToExclude);
}
exports.businessDays = businessDays;
/**
* Returns the Date when the document was created.
*
* @returns {Date} Date. The date when the current document was created.
* @example
* rosettajs.DateTime.created(); // returns Wed Aug 04 2021 12:23:17 GMT-0400 (Eastern Daylight Time) for the "Hot Chocolate" recipe document
*/
const created = () => {
return notesf().Created();
};
exports.created = created;
/**
* Returns the current operating system's time zone settings in canonical time zone format.
*
* @returns {string} Canonical time zone representing the time zone settings of the operating system.
* If the Notes time zone string is not found, the JavaScript time zone name is returned.
* @example
* rosettajs.DateTime.getCurrentTimeZone(); // returns "Z=5$DO=1$DL=3 2 1 11 1 1$ZX=40$ZN=Eastern" if in the Eastern Time Zone
*/
function getCurrentTimeZone() {
return notesf().GetCurrentTimeZone();
}
exports.getCurrentTimeZone = getCurrentTimeZone;
/**
* Returns information about language codes.
*
* @param {TextOrTextList} action Text or text list with action keyword. One of the following:
* [NotesLocale] without locale-tag returns a text list containing all the content language codes.
* [NotesLocale] with locale-tag returns a text list or value containing each specified content language code,
* or a null string if the code is not recognized. A code is recognized if it is exact regardless of case.
* If the language is recognized but not the country or region, the language code alone is returned.
* [AltNameLocale] without locale-tag returns a text list containing all the alternate name language codes.
* [AltNameLocale] with locale-tag returns a text list or value containing each specified alternate user language code,
* or a null string if the code is not recognized. A code is recognized if it is exact regardless of case.
* The country or region is ignored where it is not part of the alternate user language code (most cases).
* [LanguageName] with locale-tag returns a text list or value spelling out the language for each specified language code,
* or a null string if the code is not recognized.
* [CountryName] with locale-tag returns a text list or value spelling out the country or region for each specified language code,
* or a null string if the code has no country or region, or it is not recognized.
* [LocaleName] with locale-tag returns a text list or value spelling out the language and country (or region), if applicable,
* for each specified language code, or a null string if the code is not recognized. The country or region is in parentheses
* and immediately (no space) follows the language.
* [LocaleName] : [NotesLocale] (concatenating these two keywords) returns a text list containing, for each content language code,
* the language name, the country or region name in parentheses, a vertical bar, and the language code. This list can be used in a keyword field
* where the locale name is the name and the language code is the alias.
* [LocaleName] : [AltNameLocale] (concatenating these two keywords) returns a text list containing, for each alternate name language code,
* the language name, the country or region name in parentheses, a vertical bar, and the language tag.
* This list can be used in a keyword field where the locale name is the name and the language code is the alias.
* @param {TextOrTextList} [localeTag] A language code or list of language codes.
* af,ar,ar-AE,ar-BH,ar-DZ,ar-EG,ar-JO,ar-KW,ar-LB,ar-MA,ar-OM,ar-QA,ar-SA,ar-TN,ar-YE,be,bg,ca,cs,cy,
* da,de,de-AT,de-CH,de-DE,de-LI,de-LU,el,en,en-AU,en-CA,en-GB,en-HK,en-IE,en-IN,en-JM,en-NZ,en-PH,en-SG,
* en-US,en-ZA,es,es-AR,es-BO,es-CL,es-CO,es-CR,es-DO,es-EC,es-ES,es-GT,es-HN,es-MX,es-NI,es-PA,es-PE,
* es-PR,es-PY,es-SV,es-US,es-UY,es-VE,et,fi,fr,fr-BE,fr-CA,fr-CH,fr-FR,fr-LU,gu,he,hi,hr,hu,id,is,it,it-CH,
* it-IT,ja,kk,ko,lt,lv,mk,mr,ms,ms-MY,mt,nl,nl-BE,nl-NL,no,no-NO,ny-NO,pl,pt,pt-BR,pt-PT,ro,ro-MD,ro-RO,
* ru,sk,sl,sq,sr,sv,ta,te,th,tr,uk,vi,x-KOK,zh-CN,zh-HK,zh-MO,zh-SG,zh-TW
* @returns {TextOrTextList} Returns the requested information about the language codes. Empty string if tag is not found.
* @example
* rosettajs.DateTime.locale([LanguageName]; "fr"); // returns "French"
* @example
* rosettajs.DateTime.locale([LocaleName]; "fr-CA"); // returns "French(Canada)"
*/
function locale(action, localeTag) {
return notesf().Locale(action, localeTag);
}
exports.locale = locale;
/**
* Returns the Date when the document was last modified.
* @returns {Date} Date. The date when the current document was last modified.
* @example
* rosettajs.DateTime.modified(); // returns Mon May 22 2023 12:46:49 GMT-0400 (Eastern Daylight Time) for the "Hot Chocolate" recipe document
*/
function modified() {
return notesf().Modified();
}
exports.modified = modified;
/**
* Converts a text string to a Date value, where possible.
*
* @param {TextOrTextList} time_text The strings you want to convert to a Date objects. "Today", "Tomorrow", and "Yesterday" are the only
* legal strings to use to represent relative dates.
* @returns {Date|DateRange|Date[]|DateRange[]} Date, Date range, or list thereof. The _time_text_, converted to a Date.
* @example
* rosettajs.Text.textToTime("05/12/23"); // Returns Date for 05/12/2023
* @example
* rosettajs.Text.textToTime("Tomorrow"); // Returns Date for tomorrow
*/
function textToTime(time_text) {
return notesf().TextToTime(time_text);
}
exports.textToTime = textToTime;
/**
* Builds a Date value from separate date, time, and time zone values.
*
* @param {DateOrDateList} dateStr String, Date, or array of Strings or Dates. The date string or Date object representing
* the date you want to include in the new date-time value.
* @param {DateOrDateList} timeStr String, Date, or array of Strings or Dates. The time string or Date object representing
* the time you want to include in the new date-time value.
* @param {string} [timeZone] String. Optional. Default is 'Z' for UTC. The canonical time zone value you want to apply to the new date-time value.
* You can use a Time zone field to create this value.
* @returns {DateOrDateList} A new Date value or Date list made up of the date, time, and zone supplied as function parameters.
* @example
* rosettajs.DateTime.timeMerge("02/23/02", "17:45:00"); // returns '02/23/02 17:45:00'
*/
function timeMerge(dateStr, timeStr, timeZone) {
return notesf().TimeMerge(dateStr, timeStr, timeZone);
}
exports.timeMerge = timeMerge;
/**
* Converts a Date value to a text string, incorporating time zone information.
*
* @param {DateOrDateList} timeDate Time-date value or time-date list. The time-date value or values to be converted.
* @param {string} timeZone Canonical time zone value. You can derive a time zone value using a Notes® Time zone field.
* @param {string} format Optional. String consisting of one or more format specifiers.
* @returns {TextOrTextList} The time-date value converted to a string.
* @example
* rosettajs.DateTime.Text.timeToTextInZone("02/26/2002 03:06 PM EST", "Z=9$DO=1$DL=4 1 1 10-1 1$ZX=3$ZN=Alaskan", "D2T1S3"); // Returns "02/26/2002"
*/
function timeToTextInZone(timeDate, timeZone, format) {
return notesf().TimeToTextInZone(timeDate, timeZone, format);
}
exports.timeToTextInZone = timeToTextInZone;
/**
* Converts a canonical time zone value to a human-readable text string.
*
* @param {TextOrTextList} timezone Canonical time zone value or list thereof. Use a Notes® Time zone field
* to create a time zone value.
* @param {string} [format] String consisting of one or more of the following format specifiers:
* - S = Short time zone string,
* - A = Alias for local time zone. For example, if the zone is the same as the zone in which the system is running, returns: "Local time".
* @returns {TextOrTextList} The time-date value converted to a string. If you do not include a format specifier, a long time zone label is returned.
* @example
* rosettajs.Text.timeZoneToText("Z=9$DO=1$DL=4 1 1 10 -1 1$ZX=25$ZN=America/Anchorage", "S"); // returns "GMT-8 AKDT" (when DST is in effect)
* @example
* rosettajs.Text.timeZoneToText("Z=5$DO=1$DL=4 1 1 10 -1 1$ZX=25$ZN=America/New_York", "SA"); // returns "Local time" (when DST is in effect)
*/
function timeZoneToText(timezone, format) {
return notesf().TimeZoneToText(timezone, format);
}
exports.timeZoneToText = timeZoneToText;
/**
* Returns the time-date value that corresponds to tomorrow's date.
*
* @returns {Date} Date object. Tomorrow's date.
* @example
* rosettajs.DateTime.tomorrow(); // returns '6/7/2024' if today is June 6th, 2024
*/
function tomorrow() {
return notesf().Tomorrow();
}
exports.tomorrow = tomorrow;
/**
* Returns the time-date value that corresponds to yesterday's date.
*
* @returns {Date} Date object. Yesterday's date.
* @example
* rosettajs.DateTime.yesterday(); // returns '6/5/2024' if today is June 6th, 2024
*/
function yesterday() {
return notesf().Yesterday();
}
exports.yesterday = yesterday;
/**
* Returns the time zone setting of the current computer or of a time-date value,
* and indicates if daylight-saving time is observed.
* The time zone is represented as the number of hours that must be added to the
* time-date to convert it to Greenwich Mean Time.
*
* @param {DateOrDateList} dateOrDateList Date or date list. Optional. The date whose zone you want to know.
* You must specify both a date; otherwise, @Zone returns 0.
* @returns {NumberOrNumberList} Number or number list. The time zone, followed by a period, followed by a flag indicating daylight-saving time.
* @example
* rosettajs.DateTime.zone([1/26/94 11:00 AM]); // returns 5 if in EST
*/
function zone(dateOrDateList) {
return notesf().Zone(dateOrDateList);
}
exports.zone = zone;
/**
* Indicates the time and date when the document was last accessed by a Notes®
* client, whether for reading or editing.
*
* @throws {Error} No plans to implement
*/
function accessed() {
return notesf().Accessed();
}
exports.accessed = accessed;
//# sourceMappingURL=date-time.js.map