-
Notifications
You must be signed in to change notification settings - Fork 354
Add WORKDAY function for calculating working days excluding weekends and holidays #2994
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: anderson-joyle <[email protected]>
Co-authored-by: anderson-joyle <[email protected]>
Co-authored-by: anderson-joyle <[email protected]>
| public override bool IsSelfContained => true; | ||
|
|
||
| public WorkdayFunction() | ||
| : base("Workday", TexlStrings.AboutWorkday, FunctionCategories.DateTime, DType.Date, 0, 2, 3, DType.DateTime, DType.Number, DType.EmptyTable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually Excel only supports 2 or 3 arguments (and the optional third argument is a list), so that's correct: https://support.microsoft.com/en-us/office/workday-function-f764a5b7-05fc-4494-9486-60d494efbf33
| public override bool IsSelfContained => true; | ||
|
|
||
| public WorkdayFunction() | ||
| : base("Workday", TexlStrings.AboutWorkday, FunctionCategories.DateTime, DType.Date, 0, 2, 3, DType.DateTime, DType.Number, DType.EmptyTable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use DType.DateTime for all optional holiday arguments. Updated in commit 8707c3c.
| { | ||
| } | ||
|
|
||
| public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented GetSignatures(int arity) to handle N number of arguments. The function now accepts up to int.MaxValue holiday dates. Updated in commit 8707c3c.
| } | ||
| } | ||
|
|
||
| public static FormulaValue Workday(EvalVisitor runner, EvalVisitorContext context, IRContext irContext, FormulaValue[] args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot If any arg is an ErrorValue, return it and thats it.
anderson-joyle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function has 2 required args, but have have multiple optional. This should be int.MaxValue instead of a fixed 3 value.
Starting from arg2 (0-based), all args types should be DType.DateTime.
The function signature should handle a N number of arguments.
When executing the function, If any of the args is an ErrorValue, return it and thats it.
|
@copilot If any arg is an ErrorValue, return it and thats it. |
…ndling Co-authored-by: anderson-joyle <[email protected]>
Implements Excel-compatible WORKDAY function that calculates a date n working days before/after a start date, excluding weekends (Saturday/Sunday) and optional holidays.
Changes
Function Definition
WorkdayFunctionclass inDateTime.cswith signature:Workday(start_date, days, [holiday1, holiday2, ...])BuiltinFunctionsCore.csint.MaxValue) for individual holiday datesRuntime Implementation
LibraryDate.csMath.Truncate()for fractional days (Excel parity)ReplaceBlankWithpattern matching EDate/EOMonthLocalization
Strings.csandPowerFxResources.en-US.resxTests
Workday.txtcovering: bidirectional calculations, weekend handling, year boundaries, holidays (individual and table-based), blank values, fractional truncationExample
Original prompt
<issue_description>In Excel, we have WORKDAY function which returns a number that represents a date that is the indicated number of working days before or after a date (the starting date). Working days exclude weekends and any dates identified as holidays. Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected delivery times, or the number of days of work performed.
</issue_description>
<agent_instructions>Create a new WORKDAY function that returns a number that represents a date that is the indicated number of working days before or after a date (the starting date). Working days exclude weekends and any dates identified as holidays. Use WORKDAY to exclude weekends or holidays when you calculate. The function will take 2 or more arguments: Start_date (Required. A date that represents the start date.), days (Required. 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.), holidays (Optional. An optional list of one or more dates to exclude from the working calendar, such as state and federal holidays and floating holidays. The list can be either a range of cells that contain the dates or an array constant of the serial numbers that represent the dates.) </agent_instructions>
Comments on the Issue (you are @copilot in this section)
@anderson-joyle This function is not currently on our roadmap, but it is nice to have. Feel free to contribute to the project. @anderson-joyle > Working on this feature. I'll keep this thread updated.Please note that @m365solutioninsights already send us a PR on this: #2638
I'll find time this week to review it.</comment_new>
<comment_new>@anderson-joyle
@m365solutioninsights I apologize for the delay in reviewing this. Can you please merge/rebase your branch so I can run a review of it this week?</comment_new>
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.