@bemoje/date 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @bemoje/date
|
|
2
|
+
|
|
3
|
+
Lightweight date and time utilities for formatting, time-unit conversion, and duration measurement.
|
|
4
|
+
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://nodejs.org/api/esm.html)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @bemoje/date
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
### Date Formatting
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { dateString, today, yesterday } from '@bemoje/date'
|
|
20
|
+
|
|
21
|
+
dateString()
|
|
22
|
+
// => '2026-02-28'
|
|
23
|
+
|
|
24
|
+
dateString(new Date(2025, 0, 15))
|
|
25
|
+
// => '2025-01-15'
|
|
26
|
+
|
|
27
|
+
today()
|
|
28
|
+
// => Date object for today at 00:00:00
|
|
29
|
+
|
|
30
|
+
yesterday()
|
|
31
|
+
// => Date object for yesterday at 00:00:00
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Time Unit Conversion
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { daysToMs, hoursToMs, minutesToMs, secondsToMs } from '@bemoje/date'
|
|
38
|
+
|
|
39
|
+
daysToMs(1) // => 86400000
|
|
40
|
+
hoursToMs(2) // => 7200000
|
|
41
|
+
minutesToMs(30) // => 1800000
|
|
42
|
+
secondsToMs(45) // => 45000
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Duration & Cooldowns
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { msSinceDate, hasCooldownElapsed, Timer } from '@bemoje/date'
|
|
49
|
+
|
|
50
|
+
// Milliseconds elapsed since a date
|
|
51
|
+
const start = new Date('2026-02-01')
|
|
52
|
+
msSinceDate(start)
|
|
53
|
+
// => number of ms since Feb 1
|
|
54
|
+
|
|
55
|
+
// Check if a cooldown period has passed
|
|
56
|
+
hasCooldownElapsed(start, daysToMs(7))
|
|
57
|
+
// => true (if more than 7 days have passed)
|
|
58
|
+
|
|
59
|
+
// Stopwatch-style timer
|
|
60
|
+
const elapsed = Timer()
|
|
61
|
+
// ... do some work ...
|
|
62
|
+
elapsed()
|
|
63
|
+
// => '142ms' (human-readable duration string)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Week & Date Operations
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { getWeek, stripTime } from '@bemoje/date'
|
|
70
|
+
|
|
71
|
+
getWeek(new Date('2026-02-28'))
|
|
72
|
+
// => 9
|
|
73
|
+
|
|
74
|
+
// Remove time component from a Date
|
|
75
|
+
stripTime(new Date('2026-02-28T15:30:00'))
|
|
76
|
+
// => Date('2026-02-28T00:00:00')
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Danish Month Names
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { monthNameDa, monthNameDaRelative } from '@bemoje/date'
|
|
83
|
+
|
|
84
|
+
monthNameDa(new Date('2026-03-15'))
|
|
85
|
+
// => 'Marts'
|
|
86
|
+
|
|
87
|
+
monthNameDaRelative(new Date())
|
|
88
|
+
// => relative month name in Danish
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## API Reference
|
|
92
|
+
|
|
93
|
+
| Export | Description |
|
|
94
|
+
| --------------------- | -------------------------------------------- |
|
|
95
|
+
| `dateString` | Format date as `yyyy-MM-dd` |
|
|
96
|
+
| `today` | Today's date with time stripped |
|
|
97
|
+
| `yesterday` | Yesterday's date |
|
|
98
|
+
| `stripTime` | Remove time component from a Date |
|
|
99
|
+
| `getWeek` | ISO week number |
|
|
100
|
+
| `msSinceDate` | Milliseconds elapsed since a date |
|
|
101
|
+
| `hasCooldownElapsed` | Check if a cooldown period has passed |
|
|
102
|
+
| `Timer` | Returns a function that reports elapsed time |
|
|
103
|
+
| `daysToMs` | Convert days to milliseconds |
|
|
104
|
+
| `hoursToMs` | Convert hours to milliseconds |
|
|
105
|
+
| `minutesToMs` | Convert minutes to milliseconds |
|
|
106
|
+
| `secondsToMs` | Convert seconds to milliseconds |
|
|
107
|
+
| `monthNameDa` | Danish month name |
|
|
108
|
+
| `monthNameDaRelative` | Relative Danish month name |
|