overtime.js 831 B

1234567891011121314151617181920212223242526272829
  1. const overtime = (hours, priorHours, terminal) => {
  2. switch (terminal) {
  3. case 'LAX':
  4. case 'SFO':
  5. return californiaRules(hours)
  6. break
  7. case 'LAS':
  8. case 'PHX':
  9. return federalRules(hours, priorHours)
  10. break
  11. default:
  12. throw new Error(`Overtime rules not implemented for ${terminal}.`)
  13. }
  14. }
  15. const californiaRules = (hours) => {
  16. const regularHours = Math.min(hours, 8)
  17. const overtimeHours = Math.min(Math.max(hours - 8, 0), 4)
  18. const doubletimeHours = Math.max(hours - 12, 0)
  19. return {regularHours, overtimeHours, doubletimeHours}
  20. }
  21. const federalRules = (hours, priorHours) => {
  22. const regularHours = Math.max(Math.min(40 - priorHours, hours), 0)
  23. const overtimeHours = hours - regularHours
  24. return {regularHours, overtimeHours, doubletimeHours: 0}
  25. }
  26. module.exports = overtime