tiny-ja-date 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # tiny-ja-date
2
+
3
+ Tiny TypeScript date utilities for Japanese UI.
4
+
5
+ - 日本語の日付表示
6
+ - 日本語の相対日付表示
7
+ - 土日判定
8
+ - 次の営業日計算
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install tiny-ja-date
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import {
20
+ formatJaDate,
21
+ formatRelativeJaDate,
22
+ isWeekendJP,
23
+ nextBusinessDay,
24
+ } from "tiny-ja-date"
25
+
26
+ formatJaDate(new Date(2026, 4, 12))
27
+ // "2026年5月12日(火)"
28
+
29
+ formatRelativeJaDate(new Date(2026, 4, 15), new Date(2026, 4, 12))
30
+ // "3日後"
31
+
32
+ isWeekendJP(new Date(2026, 4, 16))
33
+ // true
34
+
35
+ nextBusinessDay(new Date(2026, 4, 15))
36
+ // Date for 2026-05-18
37
+ ```
38
+
39
+ ## API
40
+
41
+ ### `formatJaDate(date: Date | string | number): string`
42
+
43
+ Formats a date as a Japanese date label.
44
+
45
+ ```ts
46
+ formatJaDate(new Date(2026, 4, 12))
47
+ // "2026年5月12日(火)"
48
+ ```
49
+
50
+ ### `formatRelativeJaDate(date: Date | string | number, baseDate?: Date | string | number): string`
51
+
52
+ Formats a date relative to a base date.
53
+
54
+ ```ts
55
+ formatRelativeJaDate(new Date(2026, 4, 12), new Date(2026, 4, 12))
56
+ // "今日"
57
+
58
+ formatRelativeJaDate(new Date(2026, 4, 11), new Date(2026, 4, 12))
59
+ // "昨日"
60
+
61
+ formatRelativeJaDate(new Date(2026, 4, 13), new Date(2026, 4, 12))
62
+ // "明日"
63
+
64
+ formatRelativeJaDate(new Date(2026, 4, 9), new Date(2026, 4, 12))
65
+ // "3日前"
66
+
67
+ formatRelativeJaDate(new Date(2026, 4, 15), new Date(2026, 4, 12))
68
+ // "3日後"
69
+ ```
70
+
71
+ ### `isWeekendJP(date: Date | string | number): boolean`
72
+
73
+ Checks whether the date is Saturday or Sunday.
74
+
75
+ ```ts
76
+ isWeekendJP(new Date(2026, 4, 16))
77
+ // true
78
+ ```
79
+
80
+ ### `nextBusinessDay(date: Date | string | number): Date`
81
+
82
+ Returns the next business day.
83
+
84
+ The input date itself is not included.
85
+
86
+ ```ts
87
+ nextBusinessDay(new Date(2026, 4, 15))
88
+ // Date for 2026-05-18
89
+ ```
90
+
91
+ ## Note
92
+
93
+ Business day calculation excludes weekends only.
94
+
95
+ Japanese holidays are intentionally out of scope for v0.1.
96
+
97
+ ## Design policy
98
+
99
+ `tiny-ja-date` is intentionally small.
100
+
101
+ It does not:
102
+
103
+ - include Japanese holiday data
104
+ - convert time zones
105
+ - format wareki
106
+ - generate calendars
107
+ - replace date-fns or dayjs
108
+
109
+ ---
110
+
111
+ ## Live Demo
112
+
113
+ - Demo → `https://fusaihanabi.github.io/tiny-ja-date`
114
+ - npm → `https://www.npmjs.com/package/tiny-ja-date`
115
+ - GitHub → `https://github.com/fusaihanabi/tiny-ja-date`
116
+ - Official → `https://dl.fusai-hanabi.com`
117
+
118
+ ---
119
+
120
+ ## License
121
+
122
+ MIT
@@ -0,0 +1,5 @@
1
+ export type DateInput = Date | string | number;
2
+ export declare function formatJaDate(input: DateInput): string;
3
+ export declare function formatRelativeJaDate(input: DateInput, baseInput?: DateInput): string;
4
+ export declare function isWeekendJP(input: DateInput): boolean;
5
+ export declare function nextBusinessDay(input: DateInput): Date;
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ const WEEKDAYS_JA = ["日", "月", "火", "水", "木", "金", "土"];
2
+ const ONE_DAY_MS = 86400000;
3
+ function toValidDate(input) {
4
+ const date = input instanceof Date
5
+ ? new Date(input.getTime())
6
+ : new Date(input);
7
+ if (Number.isNaN(date.getTime())) {
8
+ throw new TypeError("Invalid date");
9
+ }
10
+ return date;
11
+ }
12
+ function startOfLocalDay(date) {
13
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
14
+ }
15
+ export function formatJaDate(input) {
16
+ const date = toValidDate(input);
17
+ const year = date.getFullYear();
18
+ const month = date.getMonth() + 1;
19
+ const day = date.getDate();
20
+ const weekday = WEEKDAYS_JA[date.getDay()];
21
+ return `${year}年${month}月${day}日(${weekday})`;
22
+ }
23
+ export function formatRelativeJaDate(input, baseInput = new Date()) {
24
+ const date = startOfLocalDay(toValidDate(input));
25
+ const baseDate = startOfLocalDay(toValidDate(baseInput));
26
+ const diffMs = date.getTime() - baseDate.getTime();
27
+ const diffDays = Math.round(diffMs / ONE_DAY_MS);
28
+ if (diffDays === 0)
29
+ return "今日";
30
+ if (diffDays === -1)
31
+ return "昨日";
32
+ if (diffDays === 1)
33
+ return "明日";
34
+ if (diffDays < 0)
35
+ return `${Math.abs(diffDays)}日前`;
36
+ return `${diffDays}日後`;
37
+ }
38
+ export function isWeekendJP(input) {
39
+ const date = toValidDate(input);
40
+ const day = date.getDay();
41
+ return day === 0 || day === 6;
42
+ }
43
+ export function nextBusinessDay(input) {
44
+ const date = startOfLocalDay(toValidDate(input));
45
+ date.setDate(date.getDate() + 1);
46
+ while (isWeekendJP(date)) {
47
+ date.setDate(date.getDate() + 1);
48
+ }
49
+ return date;
50
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "tiny-ja-date",
3
+ "version": "0.1.0",
4
+ "description": "Tiny TypeScript date utilities for Japanese UI.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": "vitest",
20
+ "prepublishOnly": "npm run test && npm run build"
21
+ },
22
+ "keywords": [
23
+ "japanese",
24
+ "date",
25
+ "datetime",
26
+ "format",
27
+ "relative-date",
28
+ "business-day",
29
+ "typescript"
30
+ ],
31
+ "license": "MIT",
32
+ "devDependencies": {
33
+ "typescript": "^5.0.0",
34
+ "vitest": "^4.1.6"
35
+ }
36
+ }