Part of the DumbWare suite - Why So DUMB?
A stupidly simple date parser that just works. No fancy algorithms, no complex rules - just parse dates like a human would.
npm install dumbdateparser
import DumbDateParser from 'dumbdateparser';
// Use the static method
const date = DumbDateParser.parseDate('tomorrow');
// Or create an instance
const parser = new DumbDateParser();
const date = parser.parse('next friday');
<script src="node_modules/dumbdateparser/src/browser.js"></script>
<script>
// The parser is available globally as DumbDateParser
const date = DumbDateParser.parseDate('tomorrow');
</script>
-
Relative dates:
today
tomorrow
yesterday
next week
next month
next year
-
Days of the week:
monday
(ormon
)tuesday
(ortue
,tues
)wednesday
(orwed
,weds
)thursday
(orthu
,thur
,thurs
)friday
(orfri
)saturday
(orsat
)sunday
(orsun
)
-
Next specific day:
next monday
next friday
- etc.
-
Ordinal dates:
1st of january
15th march
23rd of december
-
Simple dates:
mm/dd
mm-dd
mm.dd
-
Full dates:
yyyy/mm/dd
yyyy-mm-dd
yyyy.mm.dd
- 24-hour format:
15:00
,9:30
- 12-hour format:
3pm
,9:30am
- Time of day words:
morning
(5 AM by default)afternoon
(12 PM by default)evening
(5 PM by default)night
(8 PM by default)
The parser supports common timezone abbreviations and handles conversions automatically:
// EST input will be converted to your local timezone
const parser = new DumbDateParser();
const date = parser.parse('mar 2 at 2pm est');
// Set a default timezone for all parsing
const tzParser = new DumbDateParser({ defaultTimezone: 'pst' });
const date = tzParser.parse('tomorrow at 3pm'); // Will be interpreted as PST
Supported timezones:
- PST/PDT (Pacific Time)
- MST/MDT (Mountain Time)
- CST/CDT (Central Time)
- EST/EDT (Eastern Time)
- UTC/GMT
- BST (British Summer Time)
- CET (Central European Time)
- IST (Indian Standard Time)
If no timezone is specified, the parser assumes the input is in your local timezone.
You can override the default times for morning, afternoon, evening, and night:
const parser = new DumbDateParser({
timeDefaults: {
morning: 7, // 7 AM
afternoon: 13, // 1 PM
evening: 18, // 6 PM
night: 22 // 10 PM
}
});
You can also set these via environment variables:
DUMB_TIME_MORNING
DUMB_TIME_AFTERNOON
DUMB_TIME_EVENING
DUMB_TIME_NIGHT
const parser = new DumbDateParser();
// Different time formats
parser.parse('tomorrow at 15:00'); // 24-hour format
parser.parse('friday at 3:30pm'); // 12-hour format
parser.parse('monday morning'); // Time of day word
// Timezone handling
parser.parse('mar 2 at 2pm est'); // EST converted to local time
parser.parse('tomorrow at 3pm pst'); // PST converted to local time
parser.parse('friday at 12pm utc'); // UTC converted to local time
// Default timezone
const tzParser = new DumbDateParser({ defaultTimezone: 'est' });
tzParser.parse('tomorrow at 3pm'); // Interpreted as 3 PM EST
At DumbWare, we believe in the power of stupid simple solutions. This date parser doesn't try to be clever - it just does what you'd expect. No fancy algorithms, no complex rules, just pure, unadulterated simplicity that somehow gets the job done.
MIT
- Fork it
- Make it dumber
- Create a pull request
This is part of the DumbWare suite - a collection of stupidly simple software that somehow gets the job done. Use at your own risk, and don't blame us when it parses "next christmas" as "null" because we were too lazy to implement holiday parsing.