Skip to content

Commit aaa7438

Browse files
committed
docs: add English usage and localized zh/ja versions
1 parent 1f2dbdc commit aaa7438

3 files changed

Lines changed: 292 additions & 48 deletions

File tree

docs/usage.ja.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# timeSolver 使い方
2+
3+
このドキュメントは、`timeSolver` ライブラリの主要な関数、パラメータ、およびよく使うフォーマット例を示します。開発者が素早く始められるようにまとめています。
4+
5+
## インストールと読み込み
6+
7+
CommonJS:
8+
9+
```js
10+
const timeSolver = require('timesolver');
11+
```
12+
13+
ES Module:
14+
15+
```js
16+
import timeSolver from 'timesolver';
17+
```
18+
19+
ブラウザ(UMD バンドル):
20+
21+
```html
22+
<script src="dist/timeSolver.umd.min.js"></script>
23+
<script>
24+
// グローバルに `timeSolver` が利用可能
25+
console.log(timeSolver.getString(new Date(), 'YYYYMMDD'));
26+
</script>
27+
```
28+
29+
## 主な API の概要
30+
31+
- `timeSolver.add(date, count, unit)``date``count` 単位を加算します。
32+
- `timeSolver.subtract(date, count, unit)``date` から `count` 単位を減算します。
33+
- `timeSolver.between(d1, d2, unit)``d2 - d1` の差を `unit` で返します。
34+
- `timeSolver.equal(d1, d2)` — 2 つの日付が等しいかを判定します(文字列比較)。
35+
- `timeSolver.after(d1, d2, unit)``d1``d2` より後かを判定します(`unit` 単位)。
36+
- `timeSolver.before(d1, d2, unit)``d1``d2` より前かを判定します(`unit` 単位)。
37+
- `timeSolver.afterToday(d)` / `timeSolver.beforeToday(d)` — 今日を基準とした比較。
38+
- `timeSolver.getString(date, format)``date``format` で文字列にフォーマットします。
39+
- `timeSolver.isValid(dateString, format?)` — 日付文字列を検証します。`format` が指定されていればそれに基づいて検証します。
40+
- `timeSolver.getAbbrWeek(date)` / `timeSolver.getFullWeek(date)` — 曜日を取得(短縮形または全名)。
41+
- `timeSolver.getAbbrMonth(date)` / `timeSolver.getFullMonth(date)` — 月を取得(短縮形または全名)。
42+
- `timeSolver.getQuarterByMonth(m)` / `timeSolver.getFirstMonthByQuarter(q)` — 四半期ユーティリティ。
43+
44+
###
45+
46+
```js
47+
const d = new Date('2020-01-01T00:00:00Z');
48+
timeSolver.add(d, 1, 'D'); // 2020-01-02
49+
timeSolver.subtract(d, 2, 'H'); // 2019-12-31 22:00
50+
timeSolver.between('2020-01-01','2020-01-02','H'); // 24
51+
timeSolver.getString(d, 'YYYY-MM-DD HH:MM:SS.SSS'); // e.g. '2020-01-01 00:00:00.000'
52+
```
53+
54+
## サポートされる時間単位(`unit`
55+
56+
ライブラリは複数の文字列または略語を受け付け、内部の単位インデックスへ変換します。サポートされる値は次の通りです:
57+
58+
- `MILLISECOND` または `mill` または 指定なし(デフォルト)
59+
- `SECOND` または `S` または `s`
60+
- `MINUTE` または `MIN`
61+
- `HOUR` または `H`
62+
- `DAY` または `D`
63+
- `MONTH` または `M`
64+
- `YEAR` または `Y`
65+
66+
例:`timeSolver.add(date, 5, 'H')` は 5 時間を加算します。
67+
68+
## `getString` のサポートフォーマット
69+
70+
`timeSolver.getString(date, format)` は以下のフォーマットパターンをサポートします(大文字小文字は区別されません):
71+
72+
- `YYYY` — 年(例:`2020`
73+
- `YYYYMM``202001`
74+
- `YYYYMMDD``20200101`
75+
- `YYYY/MM/DD`, `YYYY-MM-DD`, `YYYY.MM.DD` — 一般的な区切り形式
76+
- `MMDDYYYY`, `DDMMYYYY` — 月日年または日月年の順序
77+
- 日付と時刻のフォーマット:
78+
- `YYYY/MM/DD HH:MM:SS`
79+
- `YYYY/MM/DD HH:MM:SS.SSS`(ミリ秒含む)
80+
- `YYYY-MM-DD HH:MM:SS` / `YYYY-MM-DD HH:MM:SS.SSS`
81+
- `YYYY.MM.DD HH:MM:SS` / `YYYY.MM.DD HH:MM:SS.SSS`
82+
- `YYYYMMDD HH:MM:SS` / `YYYYMMDD HH:MM:SS.SSS`
83+
- `MM/DD/YYYY HH:MM:SS` / `MM/DD/YYYY HH:MM:SS.SSS`
84+
- `MM-DD-YYYY HH:MM:SS` / `MM-DD-YYYY HH:MM:SS.SSS`
85+
- `MM.DD.YYYY HH:MM:SS` / `MM.DD.YYYY HH:MM:SS.SSS`
86+
- 時刻のみ: `HH:MM:SS` / `HH:MM:SS.SSS`
87+
88+
例:
89+
90+
```js
91+
timeSolver.getString(new Date('2020-06-15T13:45:30.123Z'), 'YYYY-MM-DD HH:MM:SS.SSS')
92+
// => "2020-06-15 13:45:30.123"
93+
```
94+
95+
## `isValid` の使い方
96+
97+
- `timeSolver.isValid('2020/01/01')``true``format` が省略された場合は `Date` 解析を使用)
98+
- `timeSolver.isValid('2020/02/30', 'YYYY/MM/DD')``false`(不正な日付)
99+
100+
`format` が指定されている場合は、ビルトインのパターンで日付(および時刻)を検証し、必要に応じて追加チェックを行います。
101+
102+
## `timeLook`(軽量プロファイラ)
103+
104+
コードの区間をマークしてレポートを出力できます:
105+
106+
```js
107+
timeSolver.timeLookStart();
108+
// ... some operation ...
109+
timeSolver.timeLook('step1');
110+
// ... another operation ...
111+
timeSolver.timeLook('step2');
112+
timeSolver.timeLookReport();
113+
```
114+
115+
レポートは各区間の経過時間と相対比率を表示し、最も時間のかかる区間をハイライトします。
116+
117+
## 追加情報
118+
119+
- 多くの関数は `Date` オブジェクトまたは `new Date(...)` で解析可能な文字列を受け取ります。
120+
- 無効な日付を入力した場合、内部で `console.error` を出力し `null` を返します。
121+
122+
必要であれば、`docs/examples/` に個別のサンプルファイルとして分割することも可能です。

docs/usage.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# timeSolver 使用說明
1+
# timeSolver Usage
22

3-
這份文件說明 `timeSolver` 函式庫的主要方法、參數與常用格式範例,方便開發者快速上手。
3+
This document describes the main functions, parameters, and common format examples for the `timeSolver` library to help developers get started quickly.
44

5-
## 安裝與引入
5+
## Installation and Import
66

77
CommonJS:
88

@@ -21,27 +21,27 @@ Browser (UMD bundle):
2121
```html
2222
<script src="dist/timeSolver.umd.min.js"></script>
2323
<script>
24-
// 全域物件 timeSolver 可直接使用
24+
// global `timeSolver` is available
2525
console.log(timeSolver.getString(new Date(), 'YYYYMMDD'));
2626
</script>
2727
```
2828

29-
## 常用方法總覽
29+
## Common API Overview
3030

31-
- `timeSolver.add(date, count, unit)``date` 上加上 `count` `unit`
32-
- `timeSolver.subtract(date, count, unit)``date` 上減去 `count` `unit`
33-
- `timeSolver.between(d1, d2, unit)`回傳 `d2 - d1` 的差距,單位為 `unit`
34-
- `timeSolver.equal(d1, d2)`判斷兩個日期是否相同(字串比對)。
35-
- `timeSolver.after(d1, d2, unit)`判斷 `d1` 是否在 `d2` 之後(以 `unit` 計算)。
36-
- `timeSolver.before(d1, d2, unit)`判斷 `d1` 是否在 `d2` 之前(以 `unit` 計算)。
37-
- `timeSolver.afterToday(d)` / `timeSolver.beforeToday(d)`相對於今天的判斷。
38-
- `timeSolver.getString(date, format)` `date` 轉成指定格式的字串。
39-
- `timeSolver.isValid(dateString, format?)`驗證字串是否為合法日期;若提供 `format`,則以指定格式驗證。
40-
- `timeSolver.getAbbrWeek(date)` / `timeSolver.getFullWeek(date)`取得星期(縮寫或全名)。
41-
- `timeSolver.getAbbrMonth(date)` / `timeSolver.getFullMonth(date)`取得月份(縮寫或全名)。
42-
- `timeSolver.getQuarterByMonth(m)` / `timeSolver.getFirstMonthByQuarter(q)`季度工具。
31+
- `timeSolver.add(date, count, unit)`Add `count` units to `date`.
32+
- `timeSolver.subtract(date, count, unit)`Subtract `count` units from `date`.
33+
- `timeSolver.between(d1, d2, unit)`Return the difference `d2 - d1` in `unit`.
34+
- `timeSolver.equal(d1, d2)`Check whether two dates are equal (string comparison).
35+
- `timeSolver.after(d1, d2, unit)`Check whether `d1` is after `d2` (by `unit`).
36+
- `timeSolver.before(d1, d2, unit)`Check whether `d1` is before `d2` (by `unit`).
37+
- `timeSolver.afterToday(d)` / `timeSolver.beforeToday(d)`Compare relative to today.
38+
- `timeSolver.getString(date, format)`Format `date` as a string using `format`.
39+
- `timeSolver.isValid(dateString, format?)`Validate a date string; if `format` is provided, validate against that format.
40+
- `timeSolver.getAbbrWeek(date)` / `timeSolver.getFullWeek(date)`Get weekday (abbr or full name).
41+
- `timeSolver.getAbbrMonth(date)` / `timeSolver.getFullMonth(date)`Get month (abbr or full name).
42+
- `timeSolver.getQuarterByMonth(m)` / `timeSolver.getFirstMonthByQuarter(q)`Quarter utilities.
4343

44-
### 範例
44+
### Examples
4545

4646
```js
4747
const d = new Date('2020-01-01T00:00:00Z');
@@ -51,57 +51,57 @@ timeSolver.between('2020-01-01','2020-01-02','H'); // 24
5151
timeSolver.getString(d, 'YYYY-MM-DD HH:MM:SS.SSS'); // e.g. '2020-01-01 00:00:00.000'
5252
```
5353

54-
## 支援的時間單位 (unit)
54+
## Supported Time Units (`unit`)
5555

56-
函式內部接受字串或縮寫,會轉成對應的單位編號。可使用的值包含:
56+
The library accepts various strings or abbreviations for units and converts them to internal unit indices. Supported values include:
5757

58-
- `MILLISECOND` `mill` 或 不給(預設)
59-
- `SECOND` `S` `s`
60-
- `MINUTE` `MIN`
61-
- `HOUR` `H`
62-
- `DAY` `D`
63-
- `MONTH` `M`
64-
- `YEAR` `Y`
58+
- `MILLISECOND` or `mill` or omitted (default)
59+
- `SECOND` or `S` or `s`
60+
- `MINUTE` or `MIN`
61+
- `HOUR` or `H`
62+
- `DAY` or `D`
63+
- `MONTH` or `M`
64+
- `YEAR` or `Y`
6565

66-
例如: `timeSolver.add(date, 5, 'H')` 表示加 5 小時。
66+
Example: `timeSolver.add(date, 5, 'H')` adds 5 hours.
6767

68-
## getString 支援的格式
68+
## `getString` Supported Formats
6969

70-
`timeSolver.getString(date, format)` 支援下列格式字串(大小寫會被標準化):
70+
`timeSolver.getString(date, format)` supports the following format patterns (case-insensitive):
7171

72-
- `YYYY`年份,例如 `2020`
72+
- `YYYY`year, e.g. `2020`
7373
- `YYYYMM``202001`
7474
- `YYYYMMDD``20200101`
75-
- `YYYY/MM/DD`, `YYYY-MM-DD`, `YYYY.MM.DD`常見日期分隔格式
76-
- `MMDDYYYY`, `DDMMYYYY`月日年或日月年順序
77-
- 帶時間的格式:
75+
- `YYYY/MM/DD`, `YYYY-MM-DD`, `YYYY.MM.DD`common separators
76+
- `MMDDYYYY`, `DDMMYYYY`month-day-year or day-month-year orders
77+
- Date & time formats:
7878
- `YYYY/MM/DD HH:MM:SS`
79-
- `YYYY/MM/DD HH:MM:SS.SSS`(含毫秒)
79+
- `YYYY/MM/DD HH:MM:SS.SSS` (milliseconds)
8080
- `YYYY-MM-DD HH:MM:SS` / `YYYY-MM-DD HH:MM:SS.SSS`
8181
- `YYYY.MM.DD HH:MM:SS` / `YYYY.MM.DD HH:MM:SS.SSS`
8282
- `YYYYMMDD HH:MM:SS` / `YYYYMMDD HH:MM:SS.SSS`
8383
- `MM/DD/YYYY HH:MM:SS` / `MM/DD/YYYY HH:MM:SS.SSS`
8484
- `MM-DD-YYYY HH:MM:SS` / `MM-DD-YYYY HH:MM:SS.SSS`
8585
- `MM.DD.YYYY HH:MM:SS` / `MM.DD.YYYY HH:MM:SS.SSS`
86-
- 時間-only `HH:MM:SS` / `HH:MM:SS.SSS`
86+
- Time-only: `HH:MM:SS` / `HH:MM:SS.SSS`
8787

88-
範例:
88+
Example:
8989

9090
```js
9191
timeSolver.getString(new Date('2020-06-15T13:45:30.123Z'), 'YYYY-MM-DD HH:MM:SS.SSS')
9292
// => "2020-06-15 13:45:30.123"
9393
```
9494

95-
## isValid 使用說明
95+
## `isValid` Usage
9696

97-
- `timeSolver.isValid('2020/01/01')``true`(若 format 未給則使用 Date 解析)
98-
- `timeSolver.isValid('2020/02/30', 'YYYY/MM/DD')``false`(不合法日期)
97+
- `timeSolver.isValid('2020/01/01')``true` (when `format` is omitted, `Date` parsing is used)
98+
- `timeSolver.isValid('2020/02/30', 'YYYY/MM/DD')``false` (invalid date)
9999

100-
`format` 被提供時,會根據內建的正規表達式驗證日期與(若含時間)時間格式,並在必要時檢查時間部分是否存在。
100+
When `format` is provided, the library validates the date (and time portion, if present) using built-in patterns and performs additional checks when necessary.
101101

102-
## timeLook(簡易效能量測)
102+
## `timeLook` (lightweight timing profiler)
103103

104-
用來標記程式執行區段並列印報表:
104+
Use `timeLook` to mark code sections and print a report:
105105

106106
```js
107107
timeSolver.timeLookStart();
@@ -112,11 +112,11 @@ timeSolver.timeLook('step2');
112112
timeSolver.timeLookReport();
113113
```
114114

115-
報表會在 console 顯示每段的花費時間與相對百分比,並標記最耗時的段落。
115+
The report prints each segment's elapsed time and relative percentage, highlighting the most time-consuming section.
116116

117-
## 其他資訊
117+
## Additional Notes
118118

119-
- 函式大多接受 `Date` 物件或可被 `new Date(...)` 解析的字串作為日期參數。
120-
- 若輸入無效日期,會在內部 `console.error` 並回傳 `null`(例如 `_v` 檢查)。
119+
- Most functions accept a `Date` object or a string parseable by `new Date(...)`.
120+
- For invalid input dates the library logs an internal `console.error` and returns `null`.
121121

122-
若你需要,我可以把這份文件翻譯成英文、或把每個方法拆成單獨的示例檔案放在 `docs/examples/`
122+
If you want, I can also split this document into separate examples under `docs/examples/`.

0 commit comments

Comments
 (0)