@lbd-sh/date-tz 1.0.5 → 1.0.6

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.
@@ -0,0 +1,70 @@
1
+ name: Release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ publish:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: write
14
+ packages: write
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v4
18
+ - name: Setup Node
19
+ uses: actions/setup-node@v4
20
+ with:
21
+ node-version: "22.x"
22
+ registry-url: "https://registry.npmjs.org/"
23
+ scope: "@lbd-sh"
24
+ - name: Configure npm authentication
25
+ env:
26
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27
+ run: |
28
+ echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
29
+ echo "always-auth=true" >> ~/.npmrc
30
+ - name: Install dependencies
31
+ run: npm ci
32
+ - name: Build library
33
+ run: npm run build
34
+ - name: Compute next patch version
35
+ id: version
36
+ run: |
37
+ set -euo pipefail
38
+ current_pkg=$(jq -r '.version' package.json)
39
+ latest=$(npm view @lbd-sh/date-tz version 2>/dev/null || echo "0.0.0")
40
+ echo "Package.json version: $current_pkg"
41
+ echo "Latest published version: $latest"
42
+ base="$latest"
43
+ IFS=. read -r maj min pat <<< "$base"
44
+ pat=$((pat + 1))
45
+ next="$maj.$min.$pat"
46
+ if [ "$next" = "$current_pkg" ]; then
47
+ # If package.json already at that version, bump again
48
+ IFS=. read -r maj min pat <<< "$next"
49
+ pat=$((pat + 1))
50
+ next="$maj.$min.$pat"
51
+ fi
52
+ echo "Next version: $next"
53
+ echo "publish_version=$next" >> "$GITHUB_OUTPUT"
54
+ - name: Bump version in package.json
55
+ run: npm version ${{ steps.version.outputs.publish_version }} --git-tag-version false
56
+ - name: Commit version bump
57
+ uses: stefanzweifel/git-auto-commit-action@v5
58
+ with:
59
+ commit_message: "chore(release): bump version to ${{ steps.version.outputs.publish_version }}"
60
+ file_pattern: |
61
+ package.json
62
+ package-lock.json
63
+ - name: Publish to npm
64
+ env:
65
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
66
+ run: npm publish --access public
67
+ - name: Create git tag
68
+ run: |
69
+ git tag "v${{ steps.version.outputs.publish_version }}"
70
+ git push --tags
@@ -0,0 +1,15 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Debug TypeScript",
6
+ "type": "node",
7
+ "request": "launch",
8
+ "program": "${workspaceFolder}/dist/index.js",
9
+ "preLaunchTask": "tsc: build",
10
+ "outFiles": ["${workspaceFolder}/dist/**/*.js"],
11
+ "sourceMaps": true,
12
+ "skipFiles": ["<node_internals>/**"]
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "editor.tabSize": 2,
4
+ "typescript.referencesCodeLens.enabled": true,
5
+ "typescript.format.semicolons": "insert",
6
+ "editor.codeActionsOnSave": {
7
+ "source.organizeImports": "always"
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "tsc: build",
6
+ "type": "shell",
7
+ "command": "tsc",
8
+ "group": "build",
9
+ "problemMatcher": ["$tsc"],
10
+ "isBackground": false
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "outDir": "dist",
6
+ "rootDir": "src",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "sourceMap": true
10
+ },
11
+ "include": ["src"]
12
+ }
package/GitVersion.yml ADDED
@@ -0,0 +1,108 @@
1
+ mode: ContinuousDeployment
2
+ major-version-bump-message: (^|\s+)(breaking|major)(:?\s+)?
3
+ minor-version-bump-message: (^|\s+)(feature|minor)(:?\s+)?
4
+ patch-version-bump-message: (^|\s+)(fix|patch)(:?\s+)?
5
+ next-version: 1.0
6
+ assembly-versioning-scheme: MajorMinorPatch
7
+ assembly-file-versioning-scheme: MajorMinorPatch
8
+ assembly-informational-format: '{InformationalVersion}'
9
+ mode: ContinuousDelivery
10
+ increment: Inherit
11
+ continuous-delivery-fallback-tag: ci
12
+ tag-prefix: '[vV]'
13
+ no-bump-message: '\+semver:\s?(none|skip)'
14
+ legacy-semver-padding: 4
15
+ build-metadata-padding: 4
16
+ commits-since-version-source-padding: 4
17
+ tag-pre-release-weight: 60000
18
+ commit-message-incrementing: Enabled
19
+ ignore:
20
+ sha: []
21
+ merge-message-formats: {}
22
+ update-build-number: true
23
+ branches:
24
+ main:
25
+ regex: ^master$|^main$
26
+ mode: ContinuousDelivery
27
+ tag: ''
28
+ increment: Patch
29
+ prevent-increment-of-merged-branch-version: true
30
+ track-merge-target: false
31
+ source-branches: [ 'develop', 'release' ]
32
+ tracks-release-branches: false
33
+ is-release-branch: false
34
+ is-mainline: true
35
+ pre-release-weight: 55000
36
+ develop:
37
+ regex: ^dev(elop)?(ment)?$
38
+ mode: ContinuousDeployment
39
+ tag: alpha
40
+ increment: Minor
41
+ prevent-increment-of-merged-branch-version: false
42
+ track-merge-target: true
43
+ source-branches: []
44
+ tracks-release-branches: true
45
+ is-release-branch: false
46
+ is-mainline: false
47
+ pre-release-weight: 0
48
+ release:
49
+ regex: ^releases?[/-]
50
+ mode: ContinuousDelivery
51
+ tag: beta
52
+ increment: None
53
+ prevent-increment-of-merged-branch-version: true
54
+ track-merge-target: false
55
+ source-branches: [ 'develop', 'main', 'support', 'release' ]
56
+ tracks-release-branches: false
57
+ is-release-branch: true
58
+ is-mainline: false
59
+ pre-release-weight: 30000
60
+ feature:
61
+ regex: ^features?[/-]
62
+ mode: ContinuousDelivery
63
+ tag: useBranchName
64
+ increment: Inherit
65
+ prevent-increment-of-merged-branch-version: false
66
+ track-merge-target: false
67
+ source-branches: [ 'develop', 'main', 'release', 'feature', 'support', 'hotfix' ]
68
+ tracks-release-branches: false
69
+ is-release-branch: false
70
+ is-mainline: false
71
+ pre-release-weight: 30000
72
+ pull-request:
73
+ regex: ^(pull|pull\-requests|pr)[/-]
74
+ mode: ContinuousDelivery
75
+ tag: PullRequest
76
+ increment: Inherit
77
+ prevent-increment-of-merged-branch-version: false
78
+ tag-number-pattern: '[/-](?<number>\d+)[-/]'
79
+ track-merge-target: false
80
+ source-branches: [ 'develop', 'main', 'release', 'feature', 'support', 'hotfix' ]
81
+ tracks-release-branches: false
82
+ is-release-branch: false
83
+ is-mainline: false
84
+ pre-release-weight: 30000
85
+ hotfix:
86
+ regex: ^hotfix(es)?[/-]
87
+ mode: ContinuousDelivery
88
+ tag: beta
89
+ increment: Patch
90
+ prevent-increment-of-merged-branch-version: false
91
+ track-merge-target: false
92
+ source-branches: [ 'develop', 'main', 'support' ]
93
+ tracks-release-branches: false
94
+ is-release-branch: false
95
+ is-mainline: false
96
+ pre-release-weight: 30000
97
+ support:
98
+ regex: ^support[/-]
99
+ mode: ContinuousDelivery
100
+ tag: ''
101
+ increment: Patch
102
+ prevent-increment-of-merged-branch-version: true
103
+ track-merge-target: false
104
+ source-branches: [ 'main' ]
105
+ tracks-release-branches: false
106
+ is-release-branch: false
107
+ is-mainline: true
108
+ pre-release-weight: 55000
package/merge.cmd ADDED
@@ -0,0 +1,18 @@
1
+ @echo off
2
+ echo Pulling develop...
3
+ git checkout develop
4
+ git pull
5
+ echo Bulding...
6
+ call npm run build
7
+ echo DONE
8
+ if %errorlevel% neq 0 exit /b %errorlevel%
9
+ echo Pushing develop...
10
+ git push
11
+ echo DONE
12
+ echo Pushing master...
13
+ git checkout master
14
+ git merge develop
15
+ git push
16
+ echo DONE
17
+ git checkout develop
18
+ echo Ready
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@lbd-sh/date-tz",
3
3
  "displayName": "Date TZ",
4
4
  "engineStrict": false,
5
- "version": "1.0.5",
5
+ "version": "1.0.6",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "scripts": {
@@ -0,0 +1,213 @@
1
+ import { DateTz } from './date-tz';
2
+
3
+ describe('DateTz', () => {
4
+ it('should create an instance with the correct date and timezone', () => {
5
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
6
+ expect(dateTz.datetime).toBe(1609459200000);
7
+ expect(dateTz.timezone).toBe(0);
8
+ });
9
+
10
+ it('should compare two DateTz instances with the same timezone', () => {
11
+ const dateTz1 = new DateTz(1609459200000, 0);
12
+ const dateTz2 = new DateTz(1609545600000, 0); // 2021-01-02 00:00:00 UTC
13
+ expect(dateTz1.compare(dateTz2)).toBeLessThan(0);
14
+ });
15
+
16
+ it('should throw an error when comparing two DateTz instances with different timezones', () => {
17
+ const dateTz1 = new DateTz(1609459200000, 0);
18
+ const dateTz2 = new DateTz(1609459200000, 1);
19
+ expect(() => dateTz1.compare(dateTz2)).toThrow('Cannot compare dates with different timezones');
20
+ });
21
+
22
+ it('should format the date correctly with the default pattern', () => {
23
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
24
+ expect(dateTz.toString()).toBe('2021-01-01 00:00:00');
25
+ });
26
+
27
+ it('should format the date correctly with a custom pattern', () => {
28
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
29
+ expect(dateTz.toString('DD/MM/YYYY')).toBe('01/01/2021');
30
+ });
31
+
32
+ it('should add minutes correctly', () => {
33
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
34
+ dateTz.add(30, 'minute');
35
+ expect(dateTz.toString()).toBe('2021-01-01 00:30:00');
36
+ });
37
+
38
+ it('should add hours correctly', () => {
39
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
40
+ dateTz.add(2, 'hour');
41
+ expect(dateTz.toString()).toBe('2021-01-01 02:00:00');
42
+ });
43
+
44
+ it('should add days correctly', () => {
45
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
46
+ dateTz.add(1, 'day');
47
+ expect(dateTz.toString()).toBe('2021-01-02 00:00:00');
48
+ });
49
+
50
+ it('should add months correctly', () => {
51
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
52
+ dateTz.add(1, 'month');
53
+ expect(dateTz.toString()).toBe('2021-02-01 00:00:00');
54
+ });
55
+
56
+ it('should add years correctly', () => {
57
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
58
+ dateTz.add(1, 'year');
59
+ expect(dateTz.toString()).toBe('2022-01-01 00:00:00');
60
+ });
61
+
62
+ it('should return the correct year', () => {
63
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
64
+ expect(dateTz.year).toBe(2021);
65
+ });
66
+
67
+ it('should return the correct month', () => {
68
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
69
+ expect(dateTz.month).toBe(0); // January
70
+ });
71
+
72
+ it('should return the correct day', () => {
73
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
74
+ expect(dateTz.day).toBe(1);
75
+ });
76
+
77
+ it('should return the correct hour', () => {
78
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
79
+ expect(dateTz.hour).toBe(0);
80
+ });
81
+
82
+ it('should return the correct minute', () => {
83
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
84
+ expect(dateTz.minute).toBe(0);
85
+ });
86
+
87
+ it('should create an instance with the correct date and timezone', () => {
88
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
89
+ expect(dateTz.datetime).toBe(1609459200000);
90
+ expect(dateTz.timezone).toBe(0);
91
+ });
92
+
93
+ it('should compare two DateTz instances with the same timezone', () => {
94
+ const dateTz1 = new DateTz(1609459200000, 0);
95
+ const dateTz2 = new DateTz(1609545600000, 0); // 2021-01-02 00:00:00 UTC
96
+ expect(dateTz1.compare(dateTz2)).toBeLessThan(0);
97
+ });
98
+
99
+ it('should throw an error when comparing two DateTz instances with different timezones', () => {
100
+ const dateTz1 = new DateTz(1609459200000, 0);
101
+ const dateTz2 = new DateTz(1609459200000, 1);
102
+ expect(() => dateTz1.compare(dateTz2)).toThrow('Cannot compare dates with different timezones');
103
+ });
104
+
105
+ it('should format the date correctly with the default pattern', () => {
106
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
107
+ expect(dateTz.toString()).toBe('2021-01-01 00:00:00');
108
+ });
109
+
110
+ it('should format the date correctly with a custom pattern', () => {
111
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
112
+ expect(dateTz.toString('DD/MM/YYYY')).toBe('01/01/2021');
113
+ });
114
+
115
+ it('should add minutes correctly', () => {
116
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
117
+ dateTz.add(30, 'minute');
118
+ expect(dateTz.toString()).toBe('2021-01-01 00:30:00');
119
+ });
120
+
121
+ it('should add hours correctly', () => {
122
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
123
+ dateTz.add(2, 'hour');
124
+ expect(dateTz.toString()).toBe('2021-01-01 02:00:00');
125
+ });
126
+
127
+ it('should add days correctly', () => {
128
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
129
+ dateTz.add(1, 'day');
130
+ expect(dateTz.toString()).toBe('2021-01-02 00:00:00');
131
+ });
132
+
133
+ it('should add months correctly', () => {
134
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
135
+ dateTz.add(1, 'month');
136
+ expect(dateTz.toString()).toBe('2021-02-01 00:00:00');
137
+ });
138
+
139
+ it('should add years correctly', () => {
140
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
141
+ dateTz.add(1, 'year');
142
+ expect(dateTz.toString()).toBe('2022-01-01 00:00:00');
143
+ });
144
+
145
+ it('should return the correct year', () => {
146
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
147
+ expect(dateTz.year).toBe(2021);
148
+ });
149
+
150
+ it('should return the correct month', () => {
151
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
152
+ expect(dateTz.month).toBe(0); // January
153
+ });
154
+
155
+ it('should return the correct day', () => {
156
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
157
+ expect(dateTz.day).toBe(1);
158
+ });
159
+
160
+ it('should return the correct hour', () => {
161
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
162
+ expect(dateTz.hour).toBe(0);
163
+ });
164
+
165
+ it('should return the correct minute', () => {
166
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
167
+ expect(dateTz.minute).toBe(0);
168
+ });
169
+
170
+ it('should parse a date string correctly', () => {
171
+ const dateTz = DateTz.parse('2021--01-01 00:00:00', 'YYYY--MM-DD HH:mm', 0);
172
+ expect(dateTz.datetime).toBe(1609459200000);
173
+ expect(dateTz.timezone).toBe(0);
174
+ });
175
+
176
+ it('should set the year correctly', () => {
177
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
178
+ dateTz.set(2022, 'year');
179
+ expect(dateTz.toString()).toBe('2022-01-01 00:00:00');
180
+ });
181
+
182
+ it('should set the month correctly', () => {
183
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
184
+ dateTz.set(2, 'month');
185
+ expect(dateTz.toString()).toBe('2021-02-01 00:00:00');
186
+ });
187
+
188
+ it('should set the day correctly', () => {
189
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
190
+ dateTz.set(2, 'day');
191
+ expect(dateTz.toString()).toBe('2021-01-02 00:00:00');
192
+ });
193
+
194
+ it('should set the hour correctly', () => {
195
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
196
+ dateTz.set(2, 'hour');
197
+ expect(dateTz.toString()).toBe('2021-01-01 02:00:00');
198
+ });
199
+
200
+ it('should set the minute correctly', () => {
201
+ const dateTz = new DateTz(1609459200000, 0); // 2021-01-01 00:00:00 UTC
202
+ dateTz.set(30, 'minute');
203
+ expect(dateTz.toString()).toBe('2021-01-01 00:30:00');
204
+ });
205
+
206
+ it('should convert timezone name to offset correctly', () => {
207
+ expect(DateTz.tzNameToOffset('PST')).toBe(-8);
208
+ });
209
+
210
+ it('should convert timezone offset to name correctly', () => {
211
+ expect(DateTz.tzOffsetToName(-8)).toBe('PST');
212
+ });
213
+ });