You can create a HolyTime instance in several ways:
// Current date and timeconst now = HolyTime.now()const alsoNow = new HolyTime()// From a date stringconst date = new HolyTime('2022-10-20')// From a Date objectconst fromDate = new HolyTime(new Date())// From a timestampconst fromTimestamp = new HolyTime(1666224000000)
// Start of time periodsconst startOfDay = HolyTime.startOf('day')const startOfWeek = HolyTime.startOf('week')const startOfMonth = HolyTime.startOf('month')const startOfYear = HolyTime.startOf('year')// End of time periodsconst endOfDay = HolyTime.endOf('day')const endOfMonth = HolyTime.endOf('month')// With timezone supportconst startOfDayNY = HolyTime.startOf('day', new Date(), 'America/New_York')// Get the next periodconst nextYear = HolyTime.next('year')const nextMonth = new HolyTime().next('month')
Here’s a practical example combining multiple features:
import HolyTime from 'holy-time'// Check if a meeting is happening soonconst meetingTime = new HolyTime('2026-03-05 15:00:00')const now = HolyTime.now()if (meetingTime.isFuture()) { const timeUntil = HolyTime.between(now, meetingTime) const hours = timeUntil.in('hours') if (hours < 1) { console.log('Meeting starts in', timeUntil.format('short')) } else if (hours < 24) { console.log('Meeting is today at', meetingTime.format('hh:mm A')) } else { console.log('Meeting is on', meetingTime.format('MMMM DD at hh:mm A')) }} else { const timeAgo = HolyTime.between(meetingTime, now) console.log('Meeting ended', timeAgo.format('long'), 'ago')}// Check if a date falls on a weekendif (meetingTime.isWeekend()) { console.log('Note: This meeting is scheduled for a weekend')}
Remember that instance methods like add(), subtract(), and set() mutate the original object. Use clone() to create a copy before modifying:
const original = HolyTime.now()const modified = original.clone().add(1, 'days')