-
Notifications
You must be signed in to change notification settings - Fork 0
fix(fields): fix issue with nil params in date-related functions [CLK-509330] #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
893df27
chore: update package-lock.json
mysza 22c84c8
test: add tests with nulls
mysza 12a328b
feat: add proxy for date functions to handle null params
mysza 33b63f8
chore: update version
mysza 36a92ab
feat: return null to all falsy values
mysza 15adcee
chore: update version
mysza e0e5d23
chore: version update
mysza 0a38864
chore: use Number.NaN as an empty result
mysza d88fd28
Update src/clickup/formulajsProxy.ts
mysza 2309db0
chore: function rename cont.
mysza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import * as formulajs from '@formulajs/formulajs'; | ||
|
|
||
| const isNil = (...args: unknown[]) => | ||
| args.some((arg) => arg === null || arg === undefined || arg === '' || arg === false); | ||
| const nullToZero = (arg: unknown) => (isNil(arg) ? 0 : arg); | ||
|
|
||
| const overrides = { | ||
| DATE: (year: unknown, month: unknown, day: unknown) => | ||
| isNil(year, month, day) ? Number.NaN : formulajs.DATE(year, month, day), | ||
| DATEVALUE: (dateText: unknown) => (isNil(dateText) ? Number.NaN : formulajs.DATEVALUE(dateText)), | ||
| DAY: (date: unknown) => (isNil(date) ? Number.NaN : formulajs.DAY(date)), | ||
| DAYS: (startDate: unknown, endDate: unknown) => | ||
| isNil(startDate, endDate) ? Number.NaN : formulajs.DAYS(startDate, endDate), | ||
| DAYS360: (startDate: unknown, endDate: unknown, method: unknown) => | ||
| isNil(startDate, endDate) ? Number.NaN : formulajs.DAYS360(startDate, endDate, method), | ||
| EDATE: (startDate: unknown, months: unknown) => | ||
| isNil(startDate) ? Number.NaN : formulajs.EDATE(startDate, nullToZero(months)), | ||
| EOMONTH: (startDate: unknown, months: unknown) => | ||
| isNil(startDate) ? Number.NaN : formulajs.EOMONTH(startDate, nullToZero(months)), | ||
| HOUR: (date: unknown) => (isNil(date) ? Number.NaN : formulajs.HOUR(date)), | ||
| INTERVAL: (seconds: unknown) => formulajs.INTERVAL(nullToZero(seconds)), | ||
| ISOWEEKNUM: (date: unknown) => (isNil(date) ? Number.NaN : formulajs.ISOWEEKNUM(date)), | ||
| MINUTE: (serialNumber: unknown) => (isNil(serialNumber) ? Number.NaN : formulajs.MINUTE(serialNumber)), | ||
| MONTH: (date: unknown) => (isNil(date) ? Number.NaN : formulajs.MONTH(date)), | ||
| SECOND: (serialNumber: unknown) => (isNil(serialNumber) ? Number.NaN : formulajs.SECOND(serialNumber)), | ||
| TIME: (hour: unknown, minute: unknown, second: unknown) => | ||
| isNil(hour, minute, second) ? Number.NaN : formulajs.TIME(hour, minute, second), | ||
| TIMEVALUE: (timeText: unknown) => (isNil(timeText) ? Number.NaN : formulajs.TIMEVALUE(timeText)), | ||
| WEEKDAY: (serialNumber: unknown, returnType: unknown) => | ||
| isNil(serialNumber) ? Number.NaN : formulajs.WEEKDAY(serialNumber, returnType), | ||
| WEEKNUM: (serialNumber: unknown, returnType: unknown) => | ||
| isNil(serialNumber) ? Number.NaN : formulajs.WEEKNUM(serialNumber, returnType), | ||
| YEAR: (date: unknown) => (isNil(date) ? Number.NaN : formulajs.YEAR(date)), | ||
| YEARFRAC: (startDate: unknown, endDate: unknown, basis: unknown) => | ||
| isNil(startDate, endDate) ? Number.NaN : formulajs.YEARFRAC(startDate, endDate, basis), | ||
| WORKDAY: (startDate: unknown, days: unknown, holidays: unknown) => | ||
| isNil(startDate) ? Number.NaN : formulajs.WORKDAY(startDate, nullToZero(days), holidays), | ||
| NETWORKDAYS: (startDate: unknown, endDate: unknown, holidays: unknown) => | ||
| isNil(startDate, endDate) ? Number.NaN : formulajs.NETWORKDAYS(startDate, endDate, holidays), | ||
| }; | ||
|
|
||
| export const formulajsProxy = new Proxy(formulajs, { | ||
| get: (target, prop) => { | ||
| if (prop in overrides) { | ||
| return overrides[prop as keyof typeof overrides]; | ||
| } | ||
| if (prop in target) { | ||
| return target[prop]; | ||
| } | ||
| return null; | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.