Issue with Date Parsing in Non-ISO Format (dd/MM/yyyy, hh:mm:ss AM/PM) #770
Labels
Status: under investigation
Issue is being investigated
Type: doc bug
Problem with the documentation (e.g., doc is out of date, unclear, confusing, or broken)
Office Scripts sample scenario: Punch clock button
Problem
The script was failing to correctly calculate the shift duration due to issues with how JavaScript's
Date
object parsed date strings in the formatdd/MM/yyyy, hh:mm:ss AM/PM
. This resulted inInvalid Date
orNaN
errors during the duration calculation.Solution:
The updated script includes a custom date parsing function that manually splits the date string into components and handles the conversion of 12-hour AM/PM times to 24-hour format. This ensures that the
Clock In
andClock Out
times are correctly parsed, and the duration is accurately calculated.Updated Code:
The text was updated successfully, but these errors were encountered: