Usage
Abyss tools include the Day.js library, which can be used in your own components. Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API.
Import Day.js
import { dayjs } from '@uhg-abyss/web/tools/dayjs';Usage examples
Below are some common examples of how to use Day.js:
const currentDate = dayjs();const dateFromIsoString = dayjs('2018-04-04T16:00:00.000Z');const dateFromUnix = dayjs(1318781876406);const dateFromString = dayjs('07/01/2025', 'MM/DD/YYYY');const dateInCurrentMonth = dayjs().date();const sevenDaysFromCurrentDate = dayjs().add(7, 'day');const millisecondsBetweenTwoDates = dayjs('2019-01-25').diff( dayjs('2018-06-05'));Installation recommendation
While Abyss provides Day.js and several common plugins out of the box, we recommend installing Day.js separately in your project if you:
- Need plugins that aren't included in Abyss
- Want to control your own Day.js version
- Have specific date/time manipulation requirements
If you only need the basic plugins we provide, you can continue using the Abyss-provided version.
Abyss default plugins
The following Day.js plugins are available in Abyss:
isSameOrBeforeisSameOrAfterisYesterdayisLeapYearisTomorrowisBetweendurationtoObjectisTodaycustomParseFormat
Example usage:
// Check if a date is between two other datesdayjs('2019-01-25').isBetween('2019-01-01', '2019-02-01');
// Convert to objectdayjs('2019-01-25').toObject();
// Check if it's todaydayjs().isToday();
// durationdayjs.duration(100);
// isBetweendayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year');
// isTomorrowdayjs().add(1, 'day').isTomorrow();
// isLeapYeardayjs('2000-01-01').isLeapYear();
// isYesterdaydayjs().add(-1, 'day').isYesterday();
// isSameOrAfterdayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year');
// isSameOrBeforedayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year');