Skip to content

Commit

Permalink
5 datetime functions (#534)
Browse files Browse the repository at this point in the history
* function interval

* day counting

* tests

* more tests

* docs

* networkdays translations

* networkdays.intl translations

* refactor

* more tests

* now with binary search

* workday implementation

* tests

* translations

* linter

* docs

* .

* .

* .

* corrected logic

* refactor

* refactor

* linter

* special case
  • Loading branch information
izulin committed Oct 3, 2020
1 parent 3ef9534 commit 7152125
Show file tree
Hide file tree
Showing 26 changed files with 813 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added 9 text functions EXACT, LOWER, UPPER, MID, T, SUBSTITUTE, REPLACE, UNICODE, UNICHAR. (#159)
- Added 5 datetime functions: INTERVAL, NETWORKDAYS, NETWORKDAYS.INTL, WORKDAY, WORKDAY.INTL. (#153)
- Added 3 information functions HLOOKUP, ROW, COLUMN. (#158)

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions docs/guide/built-in-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,21 @@ lets you design your own [custom functions](custom-functions).
| EDATE <br><Badge text="v0.2.0"/>| Date and time | Shifts the given startdate by given number of months. | EDATE(Startdate; Months) |
| EOMONTH | Date and time | Returns the date of the last day of a month which falls months away from the start date. | EOMONTH(Startdate; Months) |
| HOUR <br><Badge text="v0.2.0"/>| Date and time | Returns hour component of given time. | HOUR(Time) |
| INTERVAL | Date and time | Returns interval string from given number of seconds. | INTERVAL(Seconds) |
| ISOWEEKNUM <br><Badge text="v0.2.0"/>| Date and time | Returns an ISO week number that corresponds to the week of year. | ISOWEEKNUM(Date) |
| MINUTE <br><Badge text="v0.2.0"/>| Date and time | Returns minute component of given time. | MINUTE(Time) |
| MONTH | Date and time | Returns the month for the given date value. | MONTH(Number) |
| NETWORKDAYS | Date and time | Returns the number of working days between two given dates. | NETWORKDAYS(Date1; Date2[; Holidays]) |
| NETWORKDAYS.INTL | Date and time | Returns the number of working days between two given dates. | NETWORKDAYS.INTL(Date1; Date2[; Mode [; Holidays]]) |
| NOW <br><Badge text="v0.2.0"/>| Date and time | Returns current date + time. | NOW() |
| SECOND <br><Badge text="v0.2.0"/>| Date and time | Returns second component of given time. | SECOND(Time) |
| TIME <br><Badge text="v0.2.0"/>| Date and time | Calculates time from given hour, minute and second. | TIME(Hour; Minute; Second) |
| TIMEVALUE <br><Badge text="v0.2.0"/>| Date and time | Interprets string as time. | TIMEVALUE(Timestring) |
| TODAY <br><Badge text="v0.2.0"/>| Date and time | Returns current date. | TODAY() |
| WEEKDAY <br><Badge text="v0.2.0"/>| Date and time | Computes a number between 1-7 representing the day of week. | WEEKDAY(Date; Type) |
| WEEKNUM <br><Badge text="v0.2.0"/>| Date and time | Returns a week number that corresponds to the week of year. | WEEKNUM(Date; Type) |
| WORKDAY | Date and time | Returns the working day number of days from start day. | WORKDAY(Date, Shift[; Holidays]) |
| WORKDAY.INTL | Date and time | Returns the working day number of days from start day. | WORKDAY(Date, Shift[; Mode[; Holidays]]) |
| YEAR | Date and time | Returns the year as a number according to the internal calculation rules. | YEAR(Number) |
| YEARFRAC <br><Badge text="v0.2.0"/>| Date and time | Computes the difference between two date values, in fraction of years. | YEARFRAC(Date2; Date1[; Format]) |
| BIN2DEC | Engineering | The result is the decimal number for the binary number entered. | BIN2DEC(Number) |
Expand Down
1 change: 1 addition & 0 deletions src/error-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class ErrorMessage {
public static CharacterCodeBounds = 'Character code out of bounds.'
public static NonZero = 'Argument cannot be 0.'
public static LessThanOne = 'Argument cannot be less than 1.'
public static WeekendString = 'Incorrect weekend bitmask string.'
public static FunctionName = (arg: string) => `Function name ${arg} not recognized.`
public static NamedExpressionName = (arg: string) => `Named expression ${arg} not recognized.`
public static LicenseKey = (arg: string) => `License key is ${arg}.`
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/csCZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'IFNA',
INDEX: 'INDEX',
INT: 'CELÁ.ČÁST',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'PLATBA.ÚROK',
ISBINARY: 'ISBINARY',
ISBLANK: 'JE.PRÁZDNÉ',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'MOD',
MONTH: 'MĚSÍC',
NA: 'NEDEF',
NETWORKDAYS: 'NETWORKDAYS',
'NETWORKDAYS.INTL': 'NETWORKDAYS.INTL',
NOMINAL: 'NOMINAL',
NOT: 'NE',
NOW: 'NYNÍ',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'SVYHLEDAT',
WEEKDAY: 'DENTÝDNE',
WEEKNUM: 'WEEKNUM',
WORKDAY: 'WORKDAY',
'WORKDAY.INTL': 'WORKDAY.INTL',
XOR: 'XOR',
YEAR: 'ROK',
YEARFRAC: 'YEARFRAC',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/daDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'HVISIT',
INDEX: 'INDEKS',
INT: 'HELTAL',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'R.YDELSE',
ISBINARY: 'ISBINARY',
ISBLANK: 'ER.TOM',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'REST',
MONTH: 'MÅNED',
NA: 'IKKE.TILGÆNGELIG',
NETWORKDAYS: 'ANTAL.ARBEJDSDAGE',
'NETWORKDAYS.INTL': 'ANTAL.ARBEJDSDAGE.INTL',
NOMINAL: 'NOMINEL',
NOT: 'IKKE',
NOW: 'NU',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'LOPSLAG',
WEEKDAY: 'UGEDAG',
WEEKNUM: 'UGE.NR',
WORKDAY: 'ARBEJDSDAG',
'WORKDAY.INTL': 'ARBEJDSDAG.INTL',
XOR: 'XELLER',
YEAR: 'ÅR',
YEARFRAC: 'ÅR.BRØK',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/deDE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'WENNNV',
INDEX: 'INDEX',
INT: 'GANZZAHL',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'ZINSZ',
ISBINARY: 'ISBINARY',
ISBLANK: 'ISTLEER',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'REST',
MONTH: 'MONAT',
NA: 'NV',
NETWORKDAYS: 'NETTOARBEITSTAGE',
'NETWORKDAYS.INTL': 'NETTOARBEITSTAGE.INTL',
NOMINAL: 'NOMINAL',
NOT: 'NICHT',
NOW: 'JETZT',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'SVERWEIS',
WEEKDAY: 'WOCHENTAG',
WEEKNUM: 'KALENDERWOCHE',
WORKDAY: 'ARBEITSTAG',
'WORKDAY.INTL': 'ARBEITSTAG.INTL',
XOR: 'XODER',
YEAR: 'JAHR',
YEARFRAC: 'BRTEILJAHRE',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/enGB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'IFNA',
INDEX: 'INDEX',
INT: 'INT',
INTERVAL: 'INTERVAL',
IPMT: 'IPMT',
ISBINARY: 'ISBINARY',
ISBLANK: 'ISBLANK',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'MOD',
MONTH: 'MONTH',
NA: 'NA',
NETWORKDAYS: 'NETWORKDAYS',
'NETWORKDAYS.INTL': 'NETWORKDAYS.INTL',
NOMINAL: 'NOMINAL',
NOT: 'NOT',
NOW: 'NOW',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'VLOOKUP',
WEEKDAY: 'WEEKDAY',
WEEKNUM: 'WEEKNUM',
WORKDAY: 'WORKDAY',
'WORKDAY.INTL': 'WORKDAY.INTL',
XOR: 'XOR',
YEAR: 'YEAR',
YEARFRAC: 'YEARFRAC',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/esES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const dictionary: RawTranslationPackage = {
IFNA: 'IFNA',
INDEX: 'INDICE',
INT: 'ENTERO',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'PAGOINT',
ISBINARY: 'ISBINARY',
ISBLANK: 'ESBLANCO',
Expand Down Expand Up @@ -138,6 +139,8 @@ export const dictionary: RawTranslationPackage = {
MOD: 'RESIDUO',
MONTH: 'MES',
NA: 'NOD',
NETWORKDAYS: 'DIAS.LAB',
'NETWORKDAYS.INTL': 'DIAS.LAB.INTL',
NOMINAL: 'TASA.NOMINAL',
NOT: 'NO',
NOW: 'AHORA',
Expand Down Expand Up @@ -204,6 +207,8 @@ export const dictionary: RawTranslationPackage = {
VLOOKUP: 'BUSCARV',
WEEKDAY: 'DIASEM',
WEEKNUM: 'NUM.DE.SEMANA',
WORKDAY: 'DIA.LAB',
'WORKDAY.INTL': 'DIA.LAB.INTL',
XOR: 'XOR',
YEAR: 'AÑO',
YEARFRAC: 'FRAC.AÑO',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/fiFI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'JOSPUUTTUU',
INDEX: 'INDEKSI',
INT: 'KOKONAISLUKU',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'IPMT',
ISBINARY: 'ISBINARY',
ISBLANK: 'ONTYHJÄ',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'JAKOJ',
MONTH: 'KUUKAUSI',
NA: 'PUUTTUU',
NETWORKDAYS: 'TYÖPÄIVÄT',
'NETWORKDAYS.INTL': 'TYÖPÄIVÄT.KANSVÄL',
NOMINAL: 'KORKO.VUOSI',
NOT: 'EI',
NOW: 'NYT',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'PHAKU',
WEEKDAY: 'VIIKONPÄIVÄ',
WEEKNUM: 'VIIKKO.NRO',
WORKDAY: 'TYÖPÄIVÄ',
'WORKDAY.INTL': 'TYÖPÄIVÄ.KANSVÄL',
XOR: 'EHDOTON.TAI',
YEAR: 'VUOSI',
YEARFRAC: 'VUOSI.OSA',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/frFR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'SI.NON.DISP',
INDEX: 'INDEX',
INT: 'ENT',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'INTPER',
ISBINARY: 'ISBINARY',
ISBLANK: 'ESTVIDE',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'MOD',
MONTH: 'MOIS',
NA: 'NA',
NETWORKDAYS: 'NB.JOURS.OUVRES',
'NETWORKDAYS.INTL': 'NB.JOURS.OUVRES.INTL',
NOMINAL: 'TAUX.NOMINAL',
NOT: 'NON',
NOW: 'MAINTENANT',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'RECHERCHEV',
WEEKDAY: 'JOURSEM',
WEEKNUM: 'NO.SEMAINE',
WORKDAY: 'SERIE.JOUR.OUVRE',
'WORKDAY.INTL': 'SERIE.JOUR.OUVRE.INTL',
XOR: 'OUX',
YEAR: 'ANNEE',
YEARFRAC: 'FRACTION.ANNEE',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/huHU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'HAHIÁNYZIK',
INDEX: 'INDEX',
INT: 'INT',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'RRÉSZLET',
ISBINARY: 'ISBINARY',
ISBLANK: 'ÜRES',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'MARADÉK',
MONTH: 'HÓNAP',
NA: 'HIÁNYZIK',
NETWORKDAYS: 'ÖSSZ.MUNKANAP',
'NETWORKDAYS.INTL': 'ÖSSZ.MUNKANAP.INTL',
NOMINAL: 'NÉVLEGES',
NOT: 'NEM',
NOW: 'MOST',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'FKERES',
WEEKDAY: 'HÉT.NAPJA',
WEEKNUM: 'HÉT.SZÁMA',
WORKDAY: 'KALK.MUNKANAP',
'WORKDAY.INTL': 'KALK.MUNKANAP.INTL',
XOR: 'XVAGY',
YEAR: 'ÉV',
YEARFRAC: 'TÖRTÉV',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/itIT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'SE.NON.DISP.',
INDEX: 'INDICE',
INT: 'INT',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'INTERESSI',
ISBINARY: 'ISBINARY',
ISBLANK: 'VAL.VUOTO',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'RESTO',
MONTH: 'MESE',
NA: 'NON.DISP',
NETWORKDAYS: 'GIORNI.LAVORATIVI.TOT',
'NETWORKDAYS.INTL': 'GIORNI.LAVORATIVI.TOT.INTL',
NOMINAL: 'NOMINALE',
NOT: 'NON',
NOW: 'ADESSO',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'CERCA.VERT',
WEEKDAY: 'GIORNO.SETTIMANA',
WEEKNUM: 'NUM.SETTIMANA',
WORKDAY: 'GIORNO.LAVORATIVO',
'WORKDAY.INTL': 'GIORNO.LAVORATIVO.INTL',
XOR: 'XOR',
YEAR: 'ANNO',
YEARFRAC: 'FRAZIONE.ANNO',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/nbNO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'HVIS.IT',
INDEX: 'INDEKS',
INT: 'HELTALL',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'RAVDRAG',
ISBINARY: 'ISBINARY',
ISBLANK: 'ERTOM',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'REST',
MONTH: 'MÅNED',
NA: 'IT',
NETWORKDAYS: 'NETT.ARBEIDSDAGER',
'NETWORKDAYS.INTL': 'NETT.ARBEIDSDAGER.INTL',
NOMINAL: 'NOMINELL',
NOT: 'IKKE',
NOW: 'NÅ',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'FINN.RAD',
WEEKDAY: 'UKEDAG',
WEEKNUM: 'UKENR',
WORKDAY: 'ARBEIDSDAG',
'WORKDAY.INTL': 'ARBEIDSDAG.INTL',
XOR: 'EKSKLUSIVELLER',
YEAR: 'ÅR',
YEARFRAC: 'ÅRDEL',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/nlNL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'ALS.NB',
INDEX: 'INDEX',
INT: 'INTEGER',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'IBET',
ISBINARY: 'ISBINARY',
ISBLANK: 'ISLEEG',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'REST',
MONTH: 'MAAND',
NA: 'NB',
NETWORKDAYS: 'NETTO.WERKDAGEN',
'NETWORKDAYS.INTL': 'NETWERKDAGEN.INTL',
NOMINAL: 'NOMINALE.RENTE',
NOT: 'NIET',
NOW: 'NU',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'VERT.ZOEKEN',
WEEKDAY: 'WEEKDAG',
WEEKNUM: 'WEEKNUMMER',
WORKDAY: 'WERKDAG',
'WORKDAY.INTL': 'WERKDAG.INTL',
XOR: 'EX.OF',
YEAR: 'JAAR',
YEARFRAC: 'JAAR.DEEL',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/plPL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'JEŻELI.ND',
INDEX: 'INDEKS',
INT: 'ZAOKR.DO.CAŁK',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'IPMT',
ISBINARY: 'ISBINARY',
ISBLANK: 'CZY.PUSTA',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'MOD',
MONTH: 'MIESIĄC',
NA: 'BRAK',
NETWORKDAYS: 'DNI.ROBOCZE',
'NETWORKDAYS.INTL': 'DNI.ROBOCZE.NIESTAND',
NOMINAL: 'NOMINALNA',
NOT: 'NIE',
NOW: 'TERAZ',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'WYSZUKAJ.PIONOWO',
WEEKDAY: 'DZIEŃ.TYG',
WEEKNUM: 'NUM.TYG',
WORKDAY: 'DZIEŃ.ROBOCZY',
'WORKDAY.INTL': 'DZIEŃ.ROBOCZY.NIESTAND',
XOR: 'XOR',
YEAR: 'ROK',
YEARFRAC: 'CZĘŚĆ.ROKU',
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/languages/ptPT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const dictionary: RawTranslationPackage = {
IFNA: 'SENA',
INDEX: 'ÍNDICE',
INT: 'INT',
INTERVAL: 'INTERVAL', //FIXME
IPMT: 'IPGTO',
ISBINARY: 'ISBINARY',
ISBLANK: 'ÉCÉL.VAZIA',
Expand Down Expand Up @@ -138,6 +139,8 @@ const dictionary: RawTranslationPackage = {
MOD: 'MOD',
MONTH: 'MÊS',
NA: 'NÃO.DISP',
NETWORKDAYS: 'DIATRABALHOTOTAL',
'NETWORKDAYS.INTL': 'DIATRABALHOTOTAL.INTL',
NOMINAL: 'NOMINAL',
NOT: 'NÃO',
NOW: 'AGORA',
Expand Down Expand Up @@ -204,6 +207,8 @@ const dictionary: RawTranslationPackage = {
VLOOKUP: 'PROCV',
WEEKDAY: 'DIA.DA.SEMANA',
WEEKNUM: 'NÚMSEMANA',
WORKDAY: 'DIATRABALHO',
'WORKDAY.INTL': 'DIATRABALHO.INTL',
XOR: 'OUEXCL',
YEAR: 'ANO',
YEARFRAC: 'FRAÇÃOANO',
Expand Down
Loading

0 comments on commit 7152125

Please sign in to comment.