All templates
Date & TimeIntermediate
Get First Working Day of the Next Month
Robomotion•Updated 6 months ago

Overview
Computes the first business day of next month, skipping weekends. Useful for scheduling invoices, reports, or reminders that must fire on a working day.
Get First Working Day of the Next Month
Performing calculations with dates is an essential part of many business processes, as most reports and invoices contain time-related data. Robomotion enables you to add various time units to date values and get precise results for further processing.
What Get First Working Day of the Next Month can do
Robomotion.DateTime.Now(optLayout: 'RFC3339',optTimezoneOffset: 'Local') →msg.now.Core.Programming.Functionbuildsmsg.first_day_of_next_monthasnew Date(year, month+1, 1, 0, 0, 1).toISOString().Robomotion.DateTime.Splitonmsg.first_day_of_next_month→msg.first_parts(exposesweekday).- Branch (
Core.Programming.Function,outputs: 2) — port 0 whenmsg.day_of_weekstarts withS(Saturday/Sunday), port 1 otherwise. - Weekend branch:
Core.Dialog.MessageBoxtitledWorking DayshowsFirst working day of next month is Monday. - Weekday branch: Function composes
msg.dialog_text;Core.Dialog.MessageBoxtitledWorking day infoshows it.
Behind the scenes
- The
S-prefix test catches Saturday and Sunday in a single comparison (msg.day_of_week.charAt(0).toUpperCase() === 'S') and avoids locale-specific weekday strings when English locale is assumed. - December-to-January rollover is handled implicitly by
new Date(year, month+1, 1)— JavaScript'sDateconstructor normalises month overflow, so no manual year bump is needed. - The weekend branch does not compute Monday's actual date — it just displays the word "Monday". If the real date is required, add a loop that increments the day until
weekday === 'Monday'before the message box. - The
0, 0, 1seconds argument shifts the timestamp one second past midnight, which avoids edge cases where a subsequentSplitrounds down into the previous day under some timezone conversions.