Setting Business Times
dayjs = instanceof Dayjs
/**
* @param 1 business template. type : BusinessHoursMap
* @param 2 type (add|replace) default 'replace'. type : string
* add : will change working days as specified
* replace : will replace all working days as specified (if the day does not exist it will be set as 'null')
*/
const param1 : BusinesHoursMap = {
sunday?:[{start : "HH:mm:ss", end: "HH:mm:ss"}] | null,
...
};
const param2 : string = 'replace';
// Set Business Times in dayjs
dayjs.setBusinessTime(param1, param2);
Default Working Hours
Monday-Friday 9am - 5pm
By default, Business Times are Monday-Friday, 9am - 5pm, but you can setup as many Business Segments you want in a day.
(Jika tidak mengatur jam kerja, maka secara default akan menggunakan jam kerja senin-jumat 09:00-17:00)
// Create your Business Week definition
const businessTimes: BusinessHoursMap = {
monday: [{ start: '09:00:00', end: '17:00:00' }],
tuesday: [{ start: '09:00:00', end: '17:00:00' }],
wednesday: [{ start: '09:00:00', end: '17:00:00' }],
thursday: [{ start: '09:00:00', end: '17:00:00' }],
friday: [{ start: '09:00:00', end: '17:00:00' }],
saturday: null,
sunday: null,
}
// Set Business Times in dayjs
dayjs.setBusinessTime(businessTimes);
Always Open
There is no closing time during the week.
(24 jam sehari selama seminggu, tidak ada hari libur kecuali exceptions atau holidays sudah diatur)
// Create your Business Week definition
const businessTimes: BusinessHoursMap = {
monday: [{ start: '00:00:00', end: '24:00:00' }],
tuesday: [{ start: '00:00:00', end: '24:00:00' }],
wednesday: [{ start: '00:00:00', end: '24:00:00' }],
thursday: [{ start: '00:00:00', end: '24:00:00' }],
friday: [{ start: '00:00:00', end: '24:00:00' }],
saturday: [{ start: '00:00:00', end: '24:00:00' }],
sunday: [{ start: '00:00:00', end: '24:00:00' }],
}
// Set Business Times in dayjs
dayjs.setBusinessTime(businessTimes);
Always Close
only applies when 'exception' has been set.
(berlaku ketika exceptions sudah diatur)
// Set Business Times in dayjs
dayjs.setBusinessTime({});
// get
const businessTime = dayjs.getBusinessTime();
console.dir(businessTime);
/**
* @Result :
{
monday: null,
tuesday: null,
wednesday: null,
thursday: null,
friday: null,
saturday: null,
sunday: null,
}
*/
Customized Working Hours
Weekend template
only specified working hours.
(cuma kerja dihari sabtu dan minggu jam 08:00-18:00)
// Create your Business Week definition
const businessTimes: BusinessHoursMap = {
sunday: [{ start: '08:00:00', end: '12:00:00' }, { start: '14:00:00', end: '18:00:00' }],
saturday: [{ start: '08:00:00', end: '13:00:00' }, { start: '12:00:00', end: '18:00:00' }, { start: '20:00:00', end: '24:00:00' }], // merge overlap
}
// set
dayjs.setBusinessTime(businessTimes);
// get
const businessTime = dayjs.getBusinessTime();
console.dir(businessTime);
/**
* @Result :
{
monday: null,
tuesday: null,
wednesday: null,
thursday: null,
friday: null,
saturday: [{ start: '08:00:00', end: '12:00:00'}, { start: '14:00:00', end: '18:00:00'}],
sunday: [{ start: '08:00:00', end: '18:00:00' }, { start: '20:00:00', end: '24:00:00'}],
}
*/
type : add
The 'add' parameter is used to add working hours to the previous working hours, and will only overwrite the corresponding working hours.
(Parameter 'add' digunakan untuk menambah jam kerja ke jam kerja sebelumnya, dan hanya akan menimpa jam kerja yang sesuai)
// default working hours
const businessTimes: BusinessHoursMap = {
monday: [{ start: '09:00:00', end: '17:00:00' }],
tuesday: [{ start: '09:00:00', end: '17:00:00' }],
wednesday: [{ start: '09:00:00', end: '17:00:00' }],
thursday: [{ start: '09:00:00', end: '17:00:00' }],
friday: [{ start: '09:00:00', end: '17:00:00' }],
saturday: null,
sunday: null,
}
// set default working hour
dayjs.setBusinessTime(businessTimes);
// type add
const newTemplate: BusinessHoursMap = {
sunday: [{ start: '08:00:00', end: '18:00:00' }],
saturday: [{ start: '08:00:00', end: '18:00:00' }],
}
// set to working hour
dayjs.setBusinessTime(newTemplate, 'add');
// get
const businessTime = dayjs.getBusinessTime();
console.dir(businessTime);
/**
* @Result
{
monday: [{ start: '09:00:00', end: '17:00:00' }],
tuesday: [{ start: '09:00:00', end: '17:00:00' }],
wednesday: [{ start: '09:00:00', end: '17:00:00' }],
thursday: [{ start: '09:00:00', end: '17:00:00' }],
friday: [{ start: '09:00:00', end: '17:00:00' }],
sunday: [{ start: '08:00:00', end: '18:00:00' }],
saturday: [{ start: '08:00:00', end: '18:00:00' }],
}
*/
type : replace
The 'replace' parameter is used to add working hours to the previous working hours, and will overwrite all previous working hours. If not set, it will be made 'null'
(Parameter 'replace' digunakan untuk menambah jam kerja ke jam kerja sebelumnya, dan akan menimpa seluruh jam kerja sebelumnya. jika tidak diatur maka akan dibuat 'null')
// default working hours
const businessTimes: BusinessHoursMap = {
monday: [{ start: '09:00:00', end: '17:00:00' }],
tuesday: [{ start: '09:00:00', end: '17:00:00' }],
wednesday: [{ start: '09:00:00', end: '17:00:00' }],
thursday: [{ start: '09:00:00', end: '17:00:00' }],
friday: [{ start: '09:00:00', end: '17:00:00' }],
saturday: null,
sunday: null,
}
// set default working hour
dayjs.setBusinessTime(businessTimes);
// type replace
const newTemplate: BusinessHoursMap = {
sunday: [{ start: '08:00:00', end: '18:00:00' }],
saturday: [{ start: '08:00:00', end: '18:00:00' }],
}
// set to working hour
dayjs.setBusinessTime(newTemplate, 'replace');
// get
const businessTime = dayjs.getBusinessTime();
console.dir(businessTime);
/**
* @Result
{
monday: null,
tuesday: null,
wednesday: null,
thursday: null,
friday: null,
sunday: [{ start: '08:00:00', end: '18:00:00' }],
saturday: [{ start: '08:00:00', end: '18:00:00' }],
}
*/
Regulations
Overlap
Overlapping working hours will be merged.
(Jam kerja yang tumpang tindih akan digabungkan)
Before | After |
---|---|
[{start: '08:00:00', end:'13:00:00'}, {start: '12:00:00', end:'18:00:00'}] | [ { start: '08:00:00', end: '18:00:00' } ] |
[{start: '08:00:00', end:'12:00:00'}, {start: '12:00:00', end:'18:00:00'}, { start: '19:00:00', end: '22:00:00' }] | [{ start: '08:00:00', end: '18:00:00' }, { start: '19:00:00', end: '22:00:00' }] |
Start > End
If the start time is greater than the end time, then those working hours will be ignored (removed).
(Jika jam start lebih besar dari jam end, maka jam kerja tersebut akan diabaikan (dihilangkan))
Before | After |
---|---|
[{start: '18:00:00', end:'13:00:00'}, {start: '12:00:00', end:'18:00:00'}] | [ { start: '12:00:00', end: '18:00:00' } ] |
[{start: '18:00:00', end:'12:00:00'}] | [] |
Greater than 24:00:00
If it's greater than 24:00:00, it will be changed to 24:00:00.
(lebih besar dari jam 24, akan diubah ke jam 24)
Before | After |
---|---|
[{start: '25:00:00', end:'28:00:00'}, {start: '20:00:00', end:'24:00:00'}] | [ { start: '20:00:00', end: '24:00:00' } ] |
[{start: '22:00:00', end:'25:30:00'}] | [ { start: '22:00:00', end: '24:00:00' } ] |
Getting Business Times
Business Time
const businessTime = dayjs.getBusinessTime();
console.dir(businessTime);
/**
* @Result
{
monday: [ { start: '09:00:00', end: '17:00:00' } ],
tuesday: [ { start: '09:00:00', end: '17:00:00' } ],
wednesday: [ { start: '09:00:00', end: '17:00:00' } ],
thursday: [ { start: '09:00:00', end: '17:00:00' } ],
friday: [ { start: '09:00:00', end: '17:00:00' } ],
saturday: null,
sunday: null
}
*/
Template
Template (BusinessTime, Holidays, Exceptions)
const template = dayjs.getCurrentTemplate();
console.dir(template);
/**
* @Result
{
businessTimes: {
monday: [ { start: '09:00:00', end: '17:00:00' } ],
tuesday: [ { start: '09:00:00', end: '17:00:00' } ],
wednesday: [ { start: '09:00:00', end: '17:00:00' } ],
thursday: [ { start: '09:00:00', end: '17:00:00' } ],
friday: [ { start: '09:00:00', end: '17:00:00' } ],
saturday: null,
sunday: null
},
holidays: [],
exceptions: {}
}
*/