Registry / productivity / timeUtils

timeUtils

JSON →
library2.0.0jsnpmunverified

Lightweight date/time formatting library (~1.3KB min+gzip) using PHP-like template syntax with '#{token}' placeholders. v2.0.0 is current stable release with infrequent updates. Supports browser and Node.js via ES modules, CommonJS, and UMD. Key differentiator vs moment/luxon is tiny size and simple string templates, but lacks timezone support, relative time, and advanced date math.

npm install timeUtils
INSTALL
IMPORT
SIG · TIMEUTILS
T
timeUtils
productivityjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatDate
import { formatDate } from 'timeUtils'
import formatDate from 'timeUtils'
Named export, not default.
internationalize
import { internationalize } from 'timeUtils'
const internationalize = require('timeUtils').internationalize || require('timeUtils')
Named export, not default.
formatDate (CJS)
const formatDate = require('timeUtils').formatDate;
const timeUtils = require('timeUtils'); timeUtils.formatDate()
Require the named function directly from the module object.

Demonstrates basic usage of formatDate with day, month, date, year, time, and AM/PM tokens.

import { formatDate } from 'timeUtils'; const now = new Date('2025-03-15T10:30:00'); const formatted = formatDate(now, "Today is #{l}, #{F} #{d}, #{Y}"); console.log(formatted); // Output: Today is Saturday, March 15, 2025 const timeFormatted = formatDate(now, "Current time: #{h}:#{i}:#{s} #{A}"); console.log(timeFormatted); // Output: Current time: 10:30:00 AM
Debug
Known issues
gotchaTemplate tokens use #{ } syntax, not PHP's single-character tokens directly. Forgetting the #{} wrapper will output the token literally.
fix
Always wrap tokens in #{ } like formatDate(date, "#{Y}-#{m}-#{d}")
affects: >=0.0.0
gotchaToken names are case-sensitive. 'Y' (full year) vs 'y' (2-digit year), 'm' (month with zeros) vs 'n' (month without zeros). Mixed case leads to wrong output.
fix
Refer to the token table and use correct casing.
affects: >=0.0.0
breakingv2.0.0 changed from default export to named exports. Old code using `import timeUtils from 'timeUtils'` will break.
fix
Use named imports: `import { formatDate } from 'timeUtils'`
affects: >=2.0.0
Errors
Common errors & fixes
Uncaught TypeError: timeUtils is not a function
Trying to call the import as a function when using default import in v2+.
fix
Change to named import: `import { formatDate } from 'timeUtils'`
formatDate is not defined
Using destructured require in CommonJS incorrectly: `const { formatDate } = require('timeUtils')` - this is actually correct, but if the package is not installed, this error appears.
fix
Ensure package is installed: `npm install timeUtils`
Cannot find module 'timeUtils'
Package not installed or wrong import path.
fix
Run `npm install timeUtils` and check import path.
Unexpected token '#' in template string at formatDate call
Forgetting to quote the template string or using invalid template syntax.
fix
Ensure template is a string with `#{...}` syntax inside quotes.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
26
OpenAI (training)
1
Resources
timeUtils — npm install timeUtils · libregistry