Hour Worked Calculator

Hour Worked Calculator: Track Your Time and Earnings Accurately :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-background: #fff; –error-color: #dc3545; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); margin: 0; padding: 0; line-height: 1.6; } .container { max-width: 960px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; } h1, h2, h3 { color: var(–primary-color); text-align: center; } h1 { font-size: 2.2em; margin-bottom: 10px; } h2 { font-size: 1.8em; margin-top: 30px; margin-bottom: 15px; } h3 { font-size: 1.4em; margin-top: 20px; margin-bottom: 10px; } .loan-calc-container { width: 100%; max-width: 700px; padding: 25px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–card-background); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); margin-bottom: 30px; } .input-group { margin-bottom: 20px; width: 100%; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group input[type="time"], .input-group select { width: calc(100% – 24px); padding: 12px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; transition: border-color 0.2s ease-in-out; } .input-group input[type="number"]:focus, .input-group input[type="time"]:focus, .input-group select:focus { outline: none; border-color: var(–primary-color); box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2); } .input-group .helper-text { font-size: 0.85em; color: #6c757d; margin-top: 5px; display: block; } .input-group .error-message { color: var(–error-color); font-size: 0.8em; margin-top: 8px; display: none; /* Hidden by default */ } .input-group .error-message.visible { display: block; } .button-group { display: flex; justify-content: space-between; margin-top: 25px; } button { padding: 12px 25px; border: none; border-radius: 5px; font-size: 1em; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; margin: 5px; } .btn-calculate { background-color: var(–primary-color); color: white; } .btn-calculate:hover { background-color: #003366; transform: translateY(-2px); } .btn-reset { background-color: #6c757d; color: white; } .btn-reset:hover { background-color: #5a6268; transform: translateY(-2px); } .btn-copy { background-color: var(–success-color); color: white; } .btn-copy:hover { background-color: #218838; transform: translateY(-2px); } .results-container { width: 100%; margin-top: 30px; padding: 20px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–background-color); text-align: center; } .results-container h3 { margin-top: 0; color: var(–primary-color); } .primary-result { font-size: 2.5em; font-weight: bold; color: var(–success-color); background-color: #e9ecef; padding: 15px 20px; border-radius: 6px; margin-bottom: 15px; display: inline-block; } .intermediate-values div { margin-bottom: 8px; font-size: 1.1em; } .intermediate-values span { font-weight: bold; color: var(–primary-color); } .formula-explanation { font-size: 0.9em; color: #6c757d; margin-top: 15px; border-top: 1px dashed var(–border-color); padding-top: 15px; } #chartContainer { width: 100%; margin-top: 30px; display: flex; justify-content: center; } canvas { max-width: 100%; height: auto !important; border: 1px solid var(–border-color); border-radius: 4px; } .table-container { width: 100%; margin-top: 30px; overflow-x: auto; /* For responsiveness on small screens */ } table { width: 100%; border-collapse: collapse; margin-top: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); } table caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; caption-side: top; text-align: left; } th, td { padding: 12px 15px; text-align: right; border: 1px solid var(–border-color); } th { background-color: var(–primary-color); color: white; font-weight: bold; } td { background-color: var(–card-background); } tr:nth-child(even) td { background-color: #f2f2f2; } .article-content { width: 100%; max-width: 960px; margin: 30px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .article-content h2, .article-content h3 { text-align: left; margin-top: 25px; } .article-content p { margin-bottom: 15px; } .article-content ul, .article-content ol { margin-left: 20px; margin-bottom: 15px; } .article-content li { margin-bottom: 8px; } .article-content strong { color: var(–primary-color); } .faq-item { margin-bottom: 15px; padding: 10px; border: 1px dashed var(–border-color); border-radius: 4px; background-color: #fdfdfd; } .faq-item strong { color: var(–primary-color); cursor: pointer; display: block; margin-bottom: 5px; } .faq-item div { display: none; font-size: 0.95em; color: #555; } .faq-item.open div { display: block; } .internal-links-section { margin-top: 30px; border-top: 1px solid var(–border-color); padding-top: 20px; } .internal-links-section h3 { text-align: left; } .internal-links-section ul { list-style: none; padding: 0; } .internal-links-section li { margin-bottom: 10px; } .internal-links-section a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links-section a:hover { text-decoration: underline; } .internal-links-section p { font-size: 0.9em; color: #555; } /* Specific styling for calculator inputs */ #startTime, #endTime, #breakDuration { width: 150px; /* Adjust width for time inputs */ display: inline-block; margin-right: 10px; } #breakDurationUnit { width: auto; display: inline-block; } .time-input-group { display: flex; align-items: center; flex-wrap: wrap; /* Allow wrapping on smaller screens */ } .time-input-group .input-group { margin-bottom: 0; /* Reset margin for individual time inputs */ } .time-input-group .input-group label { margin-bottom: 5px; /* Smaller margin for time labels */ } @media (max-width: 768px) { h1 { font-size: 1.8em; } h2 { font-size: 1.5em; } .loan-calc-container, .container, .article-content { margin: 10px; padding: 15px; } .button-group { flex-direction: column; align-items: center; } button { width: 90%; margin: 5px 0; } .primary-result { font-size: 2em; } .time-input-group { flex-direction: column; align-items: flex-start; } #startTime, #endTime, #breakDuration { width: 100%; margin-right: 0; margin-bottom: 10px; } #breakDurationUnit { width: 100%; margin-top: 5px; } th, td { padding: 8px 10px; font-size: 0.9em; } }

Hour Worked Calculator

Precisely track your work hours and calculate your earnings.

Time & Earnings Calculator

Enter your pay rate per hour (e.g., 25.50).
Hours Minutes Enter break time (e.g., 0.5 for 30 mins or 30 for 30 mins).

Your Work Summary

$0.00
Total Hours Worked: 0.00
Billable Hours: 0.00
Break Time: 0 hours 0 minutes
Earnings are calculated by multiplying your hourly rate by the billable hours worked. Billable hours are total hours minus break time.
Daily Work Breakdown
Metric Value
Start Time –:–
End Time –:–
Total Time Elapsed 0h 0m
Break Duration 0h 0m
Billable Hours 0.00
Hourly Rate $0.00
Calculated Earnings $0.00

What is an Hour Worked Calculator?

An Hour Worked Calculator is a straightforward digital tool designed to help individuals and businesses accurately track and calculate the total hours worked and the corresponding earnings. It simplifies the process of timekeeping, especially for those paid by the hour or working on a project basis. This calculator takes into account start times, end times, and break durations to determine both the gross hours logged and the net billable hours. It's an essential tool for freelancers, employees working on an hourly wage, and employers who need to manage payroll accurately.

Who Should Use It:

  • Hourly Employees: To verify their paychecks and track overtime.
  • Freelancers & Gig Workers: To accurately bill clients and manage project timelines.
  • Small Business Owners: To manage employee payroll, track labor costs, and ensure fair compensation.
  • Contractors: To log hours for different projects and clients.
  • Anyone Earning an Hourly Wage: To gain clarity on their income based on time spent working.

Common Misconceptions:

  • Myth: Total hours worked always equals billable hours. Reality: Unpaid breaks are typically subtracted, meaning billable hours are often less than total hours.
  • Myth: The calculator only needs start and end times. Reality: Accurately accounting for breaks is crucial for precise earnings calculation.
  • Myth: It's just for employees. Reality: Freelancers and business owners benefit immensely from using such tools for billing and cost management.

Hour Worked Calculator Formula and Mathematical Explanation

The core function of an Hour Worked Calculator revolves around a few key calculations. It determines the total time elapsed, subtracts break durations, and then computes earnings based on an hourly rate.

1. Total Time Elapsed Calculation

This is the duration between the recorded start time and end time.

Formula: `Total Time Elapsed = End Time – Start Time`

To perform this calculation mathematically, times are often converted into minutes or seconds. For example, if start time is 09:30 and end time is 17:00:

  • End time in minutes from midnight: (17 * 60) + 0 = 1020 minutes
  • Start time in minutes from midnight: (9 * 60) + 30 = 570 minutes
  • Total Time Elapsed (minutes): 1020 – 570 = 450 minutes
  • Total Time Elapsed (hours): 450 / 60 = 7.5 hours

2. Break Time Calculation

The duration of unpaid breaks needs to be accounted for.

Formula: `Break Time = Duration Input` (converted to hours)

If the input is in minutes (e.g., 30 minutes), it's converted to hours by dividing by 60. If it's already in hours (e.g., 0.5 hours), no conversion is needed.

3. Billable Hours Calculation

This represents the actual time for which you are paid or will bill a client.

Formula: `Billable Hours = Total Time Elapsed – Break Time`

Using the example above (7.5 hours total, 0.5 hours break):

  • Billable Hours = 7.5 hours – 0.5 hours = 7.0 hours

4. Total Earnings Calculation

This is the final gross pay based on the billable hours and the agreed-upon rate.

Formula: `Total Earnings = Billable Hours * Hourly Rate`

If the hourly rate is $20:

  • Total Earnings = 7.0 hours * $20/hour = $140.00

Variable Explanations Table

Variables Used in Hour Worked Calculation
Variable Meaning Unit Typical Range
Start Time The time when work began for a specific period. Time (HH:MM) 00:00 – 23:59
End Time The time when work ended for a specific period. Time (HH:MM) 00:00 – 23:59
Break Duration The amount of time taken for unpaid breaks. Hours or Minutes 0 – Significant portion of workday
Hourly Rate The amount earned per hour of work. Currency ($) Varies widely based on profession and location
Total Time Elapsed The gross duration between start and end times. Hours Positive value
Billable Hours The net working hours after deducting breaks. Hours 0 – Total Time Elapsed
Total Earnings The final calculated income for the period. Currency ($) 0 – Billable Hours * Hourly Rate

Practical Examples (Real-World Use Cases)

Example 1: Freelance Web Developer

Sarah is a freelance web developer who charges $50 per hour. On Tuesday, she started working on a client's project at 9:00 AM and finished at 5:30 PM. She took a 45-minute lunch break. Let's calculate her earnings for the day.

  • Inputs:
    • Hourly Rate: $50.00
    • Start Time: 09:00
    • End Time: 17:30
    • Break Duration: 45 minutes
  • Calculations:
    • Total Time Elapsed: 17:30 – 09:00 = 8.5 hours
    • Break Time: 45 minutes = 0.75 hours
    • Billable Hours: 8.5 hours – 0.75 hours = 7.75 hours
    • Total Earnings: 7.75 hours * $50.00/hour = $387.50
  • Output: Sarah worked 8.5 hours, took a 0.75-hour break, resulting in 7.75 billable hours. Her earnings for the day are $387.50. This helps her accurately invoice the client.

Example 2: Retail Associate

John is a part-time retail associate earning $15 per hour. His shift started at 10:00 AM and ended at 6:00 PM. His employer policy allows for a 30-minute unpaid break.

  • Inputs:
    • Hourly Rate: $15.00
    • Start Time: 10:00
    • End Time: 18:00
    • Break Duration: 30 minutes
  • Calculations:
    • Total Time Elapsed: 18:00 – 10:00 = 8.0 hours
    • Break Time: 30 minutes = 0.5 hours
    • Billable Hours: 8.0 hours – 0.5 hours = 7.5 hours
    • Total Earnings: 7.5 hours * $15.00/hour = $112.50
  • Output: John worked 8 hours, had a 0.5-hour break, logging 7.5 billable hours. His gross pay for the shift is $112.50. This calculation is vital for paycheck verification.

Example 3: Calculating Weekly Pay

Maria works as a tutor at $25/hour. This week, she worked the following hours:

  • Monday: 9:00 AM – 1:00 PM (30 min break) = 3.5 billable hours
  • Wednesday: 2:00 PM – 6:00 PM (no break) = 4.0 billable hours
  • Friday: 10:00 AM – 12:00 PM (no break) = 2.0 billable hours
  • Total Billable Hours for the Week: 3.5 + 4.0 + 2.0 = 9.5 hours
  • Total Earnings: 9.5 hours * $25.00/hour = $237.50

Using an Hour Worked Calculator can help aggregate these daily logs into a weekly total for easier income tracking.

How to Use This Hour Worked Calculator

Our Hour Worked Calculator is designed for simplicity and accuracy. Follow these steps to get your precise work hours and earnings:

  1. Enter Your Hourly Rate: Input the amount you earn per hour into the "Hourly Rate" field. Ensure you use the correct currency format (e.g., 25.50).
  2. Specify Start and End Times: Use the "Start Time" and "End Time" selectors to input the exact times you began and finished your work session. The calculator uses a 24-hour format implicitly.
  3. Input Break Duration: Enter the total duration of any unpaid breaks you took during your work session. You can specify this in hours (e.g., 0.5 for 30 minutes) or minutes (e.g., 30 for 30 minutes) using the dropdown selector.
  4. Click "Calculate": Once all fields are filled, click the "Calculate" button.

How to Read Results:

  • Primary Highlighted Result (Total Earnings): This large, prominent number shows your calculated gross earnings for the entered time period.
  • Total Hours Worked: This displays the full duration from start to end time, including breaks.
  • Billable Hours: This is the crucial metric – it's the total hours worked minus your break time, representing the hours you will be paid for or will bill clients.
  • Break Time Display: Shows the duration of the breaks you entered, confirmed in hours and minutes.
  • Table Breakdown: The table provides a detailed summary of all entered and calculated values, including start/end times, total elapsed time, break duration, billable hours, hourly rate, and the final earnings.
  • Chart Visualization: The chart offers a visual representation, typically comparing total hours worked versus billable hours.

Decision-Making Guidance:

  • Verification: Use the calculated earnings to verify your pay stubs or client invoices.
  • Budgeting: Understand your income more precisely for better personal or business financial planning.
  • Client Billing: Ensure accurate invoicing for freelance projects based on precise billable hours.
  • Overtime Tracking: Easily calculate earnings for overtime hours by running separate calculations or adjusting inputs.
  • Cost Analysis: For businesses, use this to estimate labor costs for specific tasks or employees.

Key Factors That Affect Hour Worked Results

Several factors significantly influence the accuracy and utility of an Hour Worked Calculator's output:

  1. Accuracy of Time Entry: The most critical factor. Even small errors in start/end times or break durations can lead to discrepancies in calculated hours and earnings. Meticulous logging is key.
  2. Break Policies: Whether breaks are paid or unpaid dramatically impacts billable hours. Employers must adhere to labor laws regarding mandatory breaks. This calculator assumes unpaid breaks.
  3. Hourly Rate Accuracy: Using the correct base rate is essential. This excludes overtime premiums unless explicitly calculated separately. Ensure the rate includes any agreed-upon bonuses or is the base rate before deductions.
  4. Overtime Rules: Many jurisdictions mandate higher pay rates (e.g., 1.5x) for hours worked beyond a standard threshold (e.g., 40 hours/week). This calculator computes standard earnings; overtime calculations require separate logic or adjustments.
  5. Time Zones and Shifts Crossing Midnight: When calculating for periods spanning midnight or across different time zones, ensure the time input method correctly handles these transitions to avoid errors. Our calculator implicitly handles midnight crossings if start time is later than end time (implying it's the next day).
  6. Rounding Conventions: Different organizations may round work time entries in specific ways (e.g., to the nearest 15 minutes). The precision of the calculator (often to the minute or second) might differ from company policy, requiring adjustments.
  7. Tax Deductions and Other Withholdings: The calculator typically shows gross earnings. Actual take-home pay will be lower after taxes (income tax, social security), insurance premiums, retirement contributions, and other deductions are applied.
  8. Allowances and Bonuses: The calculator focuses purely on hours * rate. It doesn't account for fixed allowances, performance bonuses, or other forms of compensation that might be part of total remuneration.

Frequently Asked Questions (FAQ)

Q1: Is the "Break Duration" input for paid or unpaid breaks?
This calculator assumes the "Break Duration" entered is for unpaid breaks. Billable Hours are calculated by subtracting this duration from the Total Time Elapsed. If your breaks are paid, you should enter '0' for break duration.
Q2: How does the calculator handle workdays that cross midnight?
The calculator implicitly handles this. If the 'End Time' is earlier than the 'Start Time' (e.g., Start 22:00, End 06:00), it assumes the end time is on the following day and calculates the duration correctly across midnight.
Q3: Can I use this calculator for weekly or monthly pay?
Yes. You can run the calculation for each day or shift and sum the resulting "Billable Hours" and "Total Earnings" manually. For a full payroll system, you'd need a more advanced tool or integrate this logic.
Q4: What if my employer rounds my hours differently?
This calculator provides precise calculations based on exact time inputs. If your employer uses specific rounding rules (e.g., rounding to the nearest quarter-hour), you may need to manually adjust the calculated billable hours to match their policy before determining your final pay.
Q5: Does the calculator account for overtime pay?
No, this basic Hour Worked Calculator calculates earnings based on a single hourly rate. For overtime, you would typically need to calculate regular hours and overtime hours separately and apply the appropriate overtime rate (e.g., 1.5x) to the overtime hours.
Q6: How do I handle multiple breaks in a day?
Add up the duration of all your unpaid breaks and enter the total sum into the "Break Duration" field. Ensure the unit (hours or minutes) matches your input.
Q7: Can I track expenses or other costs with this calculator?
This specific calculator is designed solely for tracking worked hours and calculating gross earnings based on time and rate. It does not include functionality for tracking business expenses, mileage, or other costs. You would need a dedicated expense tracking tool for that.
Q8: What is the difference between "Total Hours Worked" and "Billable Hours"?
"Total Hours Worked" is the raw duration from your start time to your end time. "Billable Hours" are the hours you are actually compensated for, after subtracting any unpaid break time. For most hourly jobs and freelance work, "Billable Hours" determine your pay.
var chartInstance = null; // To hold the chart instance function getElement(id) { return document.getElementById(id); } function parseTime(timeStr) { var parts = timeStr.split(':'); return parseInt(parts[0], 10) * 60 + parseInt(parts[1], 10); // Convert to minutes } function formatTime(minutes) { var hours = Math.floor(minutes / 60); var mins = Math.floor(minutes % 60); return hours + "h " + mins + "m"; } function formatCurrency(amount) { return "$" + amount.toFixed(2); } function validateInput(value, id, errorId, min, max, isRequired = true) { var input = getElement(id); var errorElement = getElement(errorId); var isValid = true; errorElement.innerText = "; errorElement.classList.remove('visible'); input.style.borderColor = '#ccc'; if (isRequired && (value === null || value === ")) { errorElement.innerText = 'This field is required.'; isValid = false; } else if (!isNaN(value)) { if (value max) { errorElement.innerText = 'Value cannot be greater than ' + max + '.'; isValid = false; } } else { errorElement.innerText = 'Invalid number format.'; isValid = false; } if (!isValid) { errorElement.classList.add('visible'); input.style.borderColor = 'var(–error-color)'; } return isValid; } function calculateHours() { var hourlyRateInput = getElement('hourlyRate'); var startTimeInput = getElement('startTime'); var endTimeInput = getElement('endTime'); var breakDurationInput = getElement('breakDuration'); var breakDurationUnitSelect = getElement('breakDurationUnit'); var hourlyRateError = getElement('hourlyRateError'); var startTimeError = getElement('startTimeError'); var endTimeError = getElement('endTimeError'); var breakDurationError = getElement('breakDurationError'); var hourlyRate = parseFloat(hourlyRateInput.value); var startTimeStr = startTimeInput.value; var endTimeStr = endTimeInput.value; var breakDurationVal = parseFloat(breakDurationInput.value); var breakDurationUnit = breakDurationUnitSelect.value; var allValid = true; if (!validateInput(hourlyRate, 'hourlyRate', 'hourlyRateError', 0, Infinity)) allValid = false; if (!validateInput(startTimeStr, 'startTime', 'startTimeError', null, null, true)) allValid = false; if (!validateInput(endTimeStr, 'endTime', 'endTimeError', null, null, true)) allValid = false; if (!validateInput(breakDurationVal, 'breakDuration', 'breakDurationError', 0, Infinity)) allValid = false; if (!allValid) { // Clear results if validation fails getElement('totalEarnings').innerText = '$0.00'; getElement('totalHours').innerText = '0.00'; getElement('billableHours').innerText = '0.00'; getElement('breakTimeDisplay').innerText = '0 hours 0 minutes'; updateTable('–:–', '–:–', '0h 0m', '0h 0m', '0.00', '$0.00', '$0.00'); updateChart(0, 0); return; } var startMinutes = parseTime(startTimeStr); var endMinutes = parseTime(endTimeStr); // Handle midnight crossing if (endMinutes < startMinutes) { endMinutes += 24 * 60; // Add a full day in minutes } var totalMinutesElapsed = endMinutes – startMinutes; var totalHoursElapsed = totalMinutesElapsed / 60; var breakMinutes = 0; if (breakDurationUnit === 'minutes') { breakMinutes = breakDurationVal; } else { // hours breakMinutes = breakDurationVal * 60; } var breakHours = breakMinutes / 60; var billableMinutes = totalMinutesElapsed – breakMinutes; // Ensure billable minutes are not negative if (billableMinutes < 0) billableMinutes = 0; var billableHours = billableMinutes / 60; var totalEarnings = billableHours * hourlyRate; // Update Results Display getElement('totalEarnings').innerText = formatCurrency(totalEarnings); getElement('totalHours').innerText = totalHoursElapsed.toFixed(2); getElement('billableHours').innerText = billableHours.toFixed(2); getElement('breakTimeDisplay').innerText = formatTime(breakMinutes); // Update Table getElement('tableStartTime').innerText = startTimeStr; getElement('tableEndTime').innerText = endTimeStr; getElement('tableTotalTime').innerText = formatTime(totalMinutesElapsed); getElement('tableBreakDuration').innerText = formatTime(breakMinutes); getElement('tableBillableHours').innerText = billableHours.toFixed(2); getElement('tableHourlyRate').innerText = formatCurrency(hourlyRate); getElement('tableEarnings').innerText = formatCurrency(totalEarnings); // Update Chart updateChart(totalHoursElapsed, billableHours); } function updateChart(totalHours, billableHours) { var ctx = getElement('timeChart').getContext('2d'); // Destroy previous chart instance if it exists if (chartInstance) { chartInstance.destroy(); } chartInstance = new Chart(ctx, { type: 'bar', data: { labels: ['Hours'], datasets: [{ label: 'Total Hours Worked', data: [totalHours], backgroundColor: 'rgba(0, 74, 153, 0.7)', // Primary color borderColor: 'rgba(0, 74, 153, 1)', borderWidth: 1 }, { label: 'Billable Hours', data: [billableHours], backgroundColor: 'rgba(40, 167, 69, 0.7)', // Success color borderColor: 'rgba(40, 167, 69, 1)', borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, title: { display: true, text: 'Hours' } } }, plugins: { title: { display: true, text: 'Comparison of Total vs. Billable Hours' }, legend: { display: true, position: 'top' } } } }); } function resetForm() { getElement('hourlyRate').value = ''; getElement('startTime').value = '09:00'; getElement('endTime').value = '17:00'; getElement('breakDuration').value = '0.5'; getElement('breakDurationUnit').value = 'hours'; // Clear errors getElement('hourlyRateError').innerText = ''; getElement('hourlyRateError').classList.remove('visible'); getElement('startTimeError').innerText = ''; getElement('startTimeError').classList.remove('visible'); getElement('endTimeError').innerText = ''; getElement('endTimeError').classList.remove('visible'); getElement('breakDurationError').innerText = ''; getElement('breakDurationError').classList.remove('visible'); getElement('hourlyRate').style.borderColor = '#ccc'; getElement('startTime').style.borderColor = '#ccc'; getElement('endTime').style.borderColor = '#ccc'; getElement('breakDuration').style.borderColor = '#ccc'; // Reset results getElement('totalEarnings').innerText = '$0.00'; getElement('totalHours').innerText = '0.00'; getElement('billableHours').innerText = '0.00'; getElement('breakTimeDisplay').innerText = '0 hours 0 minutes'; updateTable('–:–', '–:–', '0h 0m', '0h 0m', '0.00', '$0.00', '$0.00'); // Clear chart if (chartInstance) { chartInstance.destroy(); chartInstance = null; } var canvas = getElement('timeChart'); var ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); } function copyResults() { var hourlyRate = parseFloat(getElement('hourlyRate').value); var totalEarnings = getElement('totalEarnings').innerText; var totalHours = getElement('totalHours').innerText; var billableHours = getElement('billableHours').innerText; var breakTimeDisplay = getElement('breakTimeDisplay').innerText; var resultText = "— Work Summary —\n"; resultText += "Hourly Rate: " + (isNaN(hourlyRate) ? "N/A" : formatCurrency(hourlyRate)) + "\n"; resultText += "Total Hours Worked: " + totalHours + " hours\n"; resultText += "Break Time: " + breakTimeDisplay + "\n"; resultText += "Billable Hours: " + billableHours + " hours\n"; resultText += "——————–\n"; resultText += "Total Earnings: " + totalEarnings + "\n"; resultText += "——————–\n"; resultText += "Calculated using: Gross Hours – Break Time = Billable Hours. Earnings = Billable Hours * Hourly Rate."; var textArea = document.createElement("textarea"); textArea.value = resultText; document.body.appendChild(textArea); textArea.select(); try { document.execCommand('copy'); alert('Results copied to clipboard!'); } catch (err) { console.error('Failed to copy: ', err); alert('Failed to copy results. Please copy manually.'); } document.body.removeChild(textArea); } function updateTable(startTime, endTime, totalTime, breakDuration, billableHours, hourlyRate, earnings) { getElement('tableStartTime').innerText = startTime; getElement('tableEndTime').innerText = endTime; getElement('tableTotalTime').innerText = totalTime; getElement('tableBreakDuration').innerText = breakDuration; getElement('tableBillableHours').innerText = billableHours; getElement('tableHourlyRate').innerText = hourlyRate; getElement('tableEarnings').innerText = earnings; } // Function to toggle FAQ answers function toggleFaq(element) { var content = element.nextElementSibling; var parent = element.parentElement; if (content.style.display === "block") { content.style.display = "none"; parent.classList.remove("open"); } else { content.style.display = "block"; parent.classList.add("open"); } } // Initialize chart on load if default values are present document.addEventListener('DOMContentLoaded', function() { calculateHours(); // Run calculation with default values on page load });

Leave a Comment