PDF Editing Issues

How to Fix Duplicate Holiday Deductions in PDF Form Date Calculations

Anum MushtaqAnum Mushtaq Oct 28, 2026 868 views

Question details

The user needs to calculate the number of working or leave days between two dates in a PDF form, properly excluding both weekend days and public holidays without counting a holiday twice if it lands on a weekend.

How to Fix Duplicate Holiday Deductions in PDF Form Date Calculations
Product
PDF Forms
Device & OS
not provided
Scenario
Calculating accurate total leave days between a start date and an end date using custom logic in an interactive PDF form.
Observed behavior
The current calculation logic deducts days twice when a listed public holiday coincides with a designated weekend day, resulting in an incorrect total day count.
Before you start

Ensure you have access to the JavaScript editor within your PDF form builder and a prepared list of the exact public holiday dates you need to exclude.

Solution 1Recommended

Implement Conditional JavaScript Logic for Holiday Exclusions

Modify the custom calculation script to verify the day of the week for each holiday, ensuring it is only deducted if it falls on a standard working day.

When calculating date differences in PDF forms, simply subtracting the total number of weekend days and then subtracting the total number of holidays often leads to overlapping deductions. To resolve this, your calculation script must iterate through the dates and apply a conditional check to prevent double-counting.

1
Open form field properties

Open your PDF document in form editing mode, right-click the 'Total Days' text field, and select 'Properties'.

2
Access the calculation script

Navigate to the 'Calculate' tab, select the 'Custom calculation script' radio button, and click the 'Edit' button to open the JavaScript editor.

3
Define the date loop

Write a JavaScript `while` or `for` loop to iterate through each day between your start date ('Date 1') and end date ('Date 2').

4
Filter out weekends

Inside the loop, use the `getDay()` method to check if the current date is a weekend. If your weekends are Thursday and Friday, check for `getDay() == 4` and `getDay() == 5`. If it is a weekend, skip to the next day without adding to the working day count.

5
Conditionally filter holidays

If the day is not a weekend, check if its date matches any date in your pre-defined array of public holidays. Only subtract the day or skip counting it if it is a verified weekday holiday. Save and close the editor.

Implement Conditional JavaScript Logic for Holiday Exclusions
Adjusting Regional Weekends: The JavaScript `getDay()` function returns 0 for Sunday through 6 for Saturday. Be sure to adjust the weekend numbers in your script to match your specific region's weekend days.
Efficient PDF Form Editing

Create and Manage Smart PDF Forms with WPS Office

WPS Office offers a comprehensive suite of PDF editing tools that make it simple to design interactive forms, manage text and date fields, and handle complex document calculations smoothly.

  1. 1. Open the PDF tool: Launch WPS Office and switch to the 'PDF' tab from the main workspace.
  2. 2. Load your document: Click 'Open' or 'Edit PDF' to load your existing PDF form document into the editor.
  3. 3. Access form controls: Navigate to the 'Form' tab on the top ribbon to insert new text fields, date fields, or modify existing calculation logic.
  4. 4. Save changes: Once your form fields and calculations are correctly configured, click 'Save' to apply and preserve your updated form settings.
Easily insert, edit, and configure interactive PDF form fieldsHighly compatible with standard PDF formats and calculation scriptsLightweight application providing a fast, user-friendly interfaceCross-platform support ensures seamless editing on Windows, Mac, and mobile devices
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF form subtract the same holiday twice?

This overlap happens when your calculation script independently subtracts all weekend days and then subtracts all dates listed in your holiday array. If a public holiday happens to fall on a weekend, it gets deducted in both steps. You must add an 'if' condition to only deduct holidays that land on weekdays.

How do I change the specific weekend days in my PDF calculation script?

You need to modify the `getDay()` function conditions in your JavaScript code. The `getDay()` method returns integers from 0 to 6, where 0 is Sunday and 6 is Saturday. Update these integer checks to match your local weekend structure (e.g., 4 and 5 for Thursday and Friday).

Can I automatically calculate the days between two dates without using code?

While basic mathematical operations can sometimes be done with built-in PDF form features, dynamically excluding specific weekends and a custom list of public holidays requires utilizing a custom JavaScript calculation script within the field's calculate properties.