Hi all
I have a bit of javascript to calculate the number of working hours between dates that I want to re-use on multiple scripts.
What I need to do is pass a start date/time value and an end date/time value to the library script. This is where it goes wrong.
The library script runs but it doesnt quite work as expected - the dates that I pass seem to get muddled at the point they move to the library. It appears that the hours and minutes of the date-time become the same for both the start and end dates,
important bits of my code:
define(['N/record', './lib/workingdays'], function(record, workingDays) { etc etc function saveRecord(scriptContext) { var preQuote = scriptContext.currentRecord; var dateAssigned = new Date(preQuote.getValue('custrecord_cs15_datetime_assigned')); var dateClosed = new Date(preQuote.getValue('custrecord_cs15_datetime_closed')); alert('before passing to Library, dateAssigned = '+dateAssigned+', dateClosed = '+dateClosed) if (dateAssigned && dateClosed){ var closeTime = workingDays.workingHours(dateAssigned, dateClosed); preQuote.setValue('custrecord_time_to_complete', closeTime); } return true; }and then my library:define([], function() { function workingHours(startDate, endDate) { alert('Working Hours Library Start '+startDate+' , '+endDate) var minutesWorked = 0; if (endDate < startDate) { return 0; } var current = startDate; var workHoursStart = 8; var workHoursEnd = 18; var includeWeekends = false; while(current <= endDate){ if(current.getHours() >= workHoursStart && current.getHours() < workHoursEnd && (includeWeekends ? current.getDay() !== 0 && current.getDay() !== 6 : true)){ minutesWorked++; } current.setTime(current.getTime() + 1000 * 60); } return twoDP(minutesWorked / 60); } function twoDP(number) { return Math.round(number*100)/100; } return { workingHours : workingHours }; });so, where I have dareAssigned and dateClosed, the dates are correct, but in the library script right from the beginning, the dates are incorrect... I am not sure where to begin with this - any help would be appreciated!Peter