Working Hours
Try in Playground →Business hours calculations with break support
Import
import { ... } from 'ts-time-utils/workingHours'; Examples
Business Hours
Calculate working time accounting for schedules
import { isWorkingTime, addWorkingDays, workingDaysBetween } from 'ts-time-utils/workingHours';
// Define working hours config
const config = {
workDays: [1, 2, 3, 4, 5], // Mon-Fri
startHour: 9,
endHour: 17,
breaks: [{ start: 12, end: 13 }] // Lunch break
};
// Check if currently working time
const monday10am = new Date('2025-09-15T10:00:00');
const saturday = new Date('2025-09-13T10:00:00');
const lunchTime = new Date('2025-09-15T12:30:00');
console.log('Mon 10am working?', isWorkingTime(monday10am, config));
// true
console.log('Saturday working?', isWorkingTime(saturday, config));
// false
console.log('During lunch?', isWorkingTime(lunchTime, config));
// false (during break)
// Add working days (skips weekends)
const friday = new Date('2025-09-12');
const afterWorkDays = addWorkingDays(friday, 3, config);
console.log('3 working days after Friday:', afterWorkDays.toDateString());
// Wednesday (skips Sat, Sun)
// Count working days between dates
const start = new Date('2025-09-01');
const end = new Date('2025-09-30');
console.log('Working days in Sep:', workingDaysBetween(start, end, config));