This project contains two scripts, net-hours.gs
and night-hours.gs
, which are designed to be used in a Google Sheets spreadsheet to calculate net working hours and night shift hours.
The net-hours.gs
script calculates the net working hours based on the total working hours recorded in the spreadsheet. The script performs the following actions:
- Retrieve the active sheet in the Google Sheets spreadsheet.
- Define the
endRow
variable as 11. (Note: You can modify this value according to your specific requirements.) - Iterate through rows 2 to
endRow
. - Retrieve the working hours from column 6 and store it in the workingHours variable.
- Based on the value of
workingHours
, deduct specific amounts of hours to calculate the net working hours and update the value in column 7.
The night-hours.gs
script calculates the night shift hours based on the shift start and end times recorded in the spreadsheet. The script performs the following actions:
- Define the nightStart and nightEnd variables as 20 and 5, respectively. (Note: You can modify these values to match your night shift timings.)
- Retrieve the active sheet in the Google Sheets spreadsheet.
- Define the endRow variable as 11. (Note: You can modify this value according to your specific requirements.)
- Iterate through rows 2 to endRow.
- Retrieve the shift start and end times from columns 3 and 4, respectively.
- Calculate the night shift hours by comparing the shift times with the nightStart and nightEnd values and update the value in column 5.
- Open the Google Sheets spreadsheet where you want to use these scripts.
- Click on "Extensions" in the menu bar and select "Apps Script".
- In the Apps Script editor, paste the contents of
net-hours.gs
into a new script file named "net-hours.gs". - Repeat the above step for night-hours.gs, creating a new script file named "night-hours.gs".
- Save the scripts.
- Close the Apps Script editor.
- Use the
net-hours
andnight-hours
functions in your Google Sheets spreadsheet to calculate the net working hours and night shift hours, respectively.
Please note that the provided information assumes a basic understanding of Google Apps Script and Google Sheets. Make sure to adjust the script and modify any values according to your specific requirements before using it.