2.0.0 • Published 2 years ago
@beauwest/business-date-parser v2.0.0
Business Date Parser 
An opinionated, zero-dependency, fast user input parser for date & times. This module is designed to process & parse user input into a Javascript date object.
Date Format Examples
c: Current Datey: Yesterdayt: Tomorrowf: First day of the monthl: Last day of the month+20: 20 days from now-20: 20 days ago15: The 15th day of the current month4/15: The 15th day of April of the current year4/15/2020: April 15th, 20205-3-18: May 3rd, 20182025-03-01: March 1st, 2025
Time Format Examples
c: Current Time+20: 20 minutes from now-20: 20 minutes ago2: 2:00 PM02: 2:00 AM2a: 2:00 AM2:45: 2:45 PM2:45a: 2:45 AM530: 5:30 PM8:22:34.028: 8:22:34.028 AM
Date & Time format examples
- Date and time parsing splits based on the first space encountered.
y 5p: Yesterday at 5:00PMl 8a: Last day of the month at 8:00AM2025-03-01 8:22:34.028: March 1st, 2025 at 8:22:34.028 AM
Anything that does not match the rule-based parsing will fall back to Javascript's built-in Date.parse().
Installing
npm i @beauwest/business-date-parserGetting Started
import {parseDate, parseTime, parseDateAndTime} from 'business-date-parser';
const theFifth = parseDate('5');
const threeDaysFromNow = parseDate('+3');
const quittingTime = parseTime('5');
const snackTime = parseTime('2:30p');
const snackTimeThreeDaysFromNow = parseTime('+3 2:30p');
// Will prefer time parsing when no date part is found in a dateAndTime string
const preferTime = parseDateAndTime('9a', {preferTime: true});
// Default to a specific date when preferring time parsing and there is no date part.
const preferTimeWithSpecificDate = parseDateAndTime('9a', {preferTime: true, defaultDate: '2025-03-01'});1.0.20
2 years ago
2.0.0
2 years ago
1.0.19
3 years ago
1.0.18
3 years ago
1.0.17
3 years ago
1.0.16
4 years ago
1.0.15
4 years ago
1.0.14
4 years ago
1.0.13
4 years ago
1.0.12
4 years ago
1.0.11
4 years ago
1.0.10
4 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.2
5 years ago
1.0.3
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago