rrule-rust 2.0.0-next.3 → 2.0.0-next.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.
- package/index.js +62 -4
- package/package.json +22 -18
- package/.eslintrc.js +0 -58
- package/.prettierrc +0 -4
- package/.releaserc +0 -47
- package/.yarnrc.yml +0 -1
- package/Cargo.toml +0 -22
- package/benchmark/.gitignore +0 -3
- package/benchmark/index.ts +0 -59
- package/build.rs +0 -5
- package/jest.config.ts +0 -7
- package/src/js/frequency.rs +0 -40
- package/src/js/month.rs +0 -56
- package/src/js/n_weekday.rs +0 -36
- package/src/js/rrule.rs +0 -275
- package/src/js/rrule_datetime.rs +0 -128
- package/src/js/rrule_set.rs +0 -258
- package/src/js/rrule_timezone.rs +0 -52
- package/src/js/weekday.rs +0 -40
- package/src/js.rs +0 -17
- package/src/lib.rs +0 -1
- package/tsconfig.eslint.json +0 -6
- package/tsconfig.json +0 -24
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ function isMusl() {
|
|
|
17
17
|
// For Node 10
|
|
18
18
|
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
19
19
|
try {
|
|
20
|
-
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
20
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
21
21
|
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
22
22
|
} catch (e) {
|
|
23
23
|
return true
|
|
@@ -224,14 +224,72 @@ switch (platform) {
|
|
|
224
224
|
}
|
|
225
225
|
break
|
|
226
226
|
case 'arm':
|
|
227
|
+
if (isMusl()) {
|
|
228
|
+
localFileExisted = existsSync(
|
|
229
|
+
join(__dirname, 'rrule-rust.linux-arm-musleabihf.node')
|
|
230
|
+
)
|
|
231
|
+
try {
|
|
232
|
+
if (localFileExisted) {
|
|
233
|
+
nativeBinding = require('./rrule-rust.linux-arm-musleabihf.node')
|
|
234
|
+
} else {
|
|
235
|
+
nativeBinding = require('@rrule-rust/lib-linux-arm-musleabihf')
|
|
236
|
+
}
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadError = e
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
localFileExisted = existsSync(
|
|
242
|
+
join(__dirname, 'rrule-rust.linux-arm-gnueabihf.node')
|
|
243
|
+
)
|
|
244
|
+
try {
|
|
245
|
+
if (localFileExisted) {
|
|
246
|
+
nativeBinding = require('./rrule-rust.linux-arm-gnueabihf.node')
|
|
247
|
+
} else {
|
|
248
|
+
nativeBinding = require('@rrule-rust/lib-linux-arm-gnueabihf')
|
|
249
|
+
}
|
|
250
|
+
} catch (e) {
|
|
251
|
+
loadError = e
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
break
|
|
255
|
+
case 'riscv64':
|
|
256
|
+
if (isMusl()) {
|
|
257
|
+
localFileExisted = existsSync(
|
|
258
|
+
join(__dirname, 'rrule-rust.linux-riscv64-musl.node')
|
|
259
|
+
)
|
|
260
|
+
try {
|
|
261
|
+
if (localFileExisted) {
|
|
262
|
+
nativeBinding = require('./rrule-rust.linux-riscv64-musl.node')
|
|
263
|
+
} else {
|
|
264
|
+
nativeBinding = require('@rrule-rust/lib-linux-riscv64-musl')
|
|
265
|
+
}
|
|
266
|
+
} catch (e) {
|
|
267
|
+
loadError = e
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
localFileExisted = existsSync(
|
|
271
|
+
join(__dirname, 'rrule-rust.linux-riscv64-gnu.node')
|
|
272
|
+
)
|
|
273
|
+
try {
|
|
274
|
+
if (localFileExisted) {
|
|
275
|
+
nativeBinding = require('./rrule-rust.linux-riscv64-gnu.node')
|
|
276
|
+
} else {
|
|
277
|
+
nativeBinding = require('@rrule-rust/lib-linux-riscv64-gnu')
|
|
278
|
+
}
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadError = e
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
break
|
|
284
|
+
case 's390x':
|
|
227
285
|
localFileExisted = existsSync(
|
|
228
|
-
join(__dirname, 'rrule-rust.linux-
|
|
286
|
+
join(__dirname, 'rrule-rust.linux-s390x-gnu.node')
|
|
229
287
|
)
|
|
230
288
|
try {
|
|
231
289
|
if (localFileExisted) {
|
|
232
|
-
nativeBinding = require('./rrule-rust.linux-
|
|
290
|
+
nativeBinding = require('./rrule-rust.linux-s390x-gnu.node')
|
|
233
291
|
} else {
|
|
234
|
-
nativeBinding = require('@rrule-rust/lib-linux-
|
|
292
|
+
nativeBinding = require('@rrule-rust/lib-linux-s390x-gnu')
|
|
235
293
|
}
|
|
236
294
|
} catch (e) {
|
|
237
295
|
loadError = e
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrule-rust",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.6",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"keywords": [
|
|
@@ -29,17 +29,19 @@
|
|
|
29
29
|
"aarch64-unknown-linux-musl",
|
|
30
30
|
"aarch64-pc-windows-msvc",
|
|
31
31
|
"armv7-unknown-linux-gnueabihf",
|
|
32
|
+
"armv7-unknown-linux-musleabihf",
|
|
32
33
|
"x86_64-unknown-linux-musl",
|
|
33
34
|
"x86_64-unknown-freebsd",
|
|
34
35
|
"i686-pc-windows-msvc",
|
|
35
36
|
"armv7-linux-androideabi",
|
|
36
|
-
"universal-apple-darwin"
|
|
37
|
+
"universal-apple-darwin",
|
|
38
|
+
"riscv64gc-unknown-linux-gnu"
|
|
37
39
|
]
|
|
38
40
|
}
|
|
39
41
|
},
|
|
40
42
|
"license": "MIT",
|
|
41
43
|
"devDependencies": {
|
|
42
|
-
"@napi-rs/cli": "^2.
|
|
44
|
+
"@napi-rs/cli": "^2.18.2",
|
|
43
45
|
"@semantic-release/git": "^10.0.1",
|
|
44
46
|
"@types/jest": "^29.5.0",
|
|
45
47
|
"@types/node": "^18.15.5",
|
|
@@ -82,23 +84,25 @@
|
|
|
82
84
|
"version": "napi version",
|
|
83
85
|
"benchmark": "ts-node ./benchmark/index.ts",
|
|
84
86
|
"lint": "cargo fmt --all -- --check && eslint \"**/*.{js,ts,json}\" --max-warnings=0",
|
|
85
|
-
"lint:fix": "cargo fmt --all &&
|
|
87
|
+
"lint:fix": "cargo fmt --all && npm run lint --fix",
|
|
86
88
|
"lint:fix-staged": "lint-staged"
|
|
87
89
|
},
|
|
88
90
|
"optionalDependencies": {
|
|
89
|
-
"@rrule-rust/lib-win32-x64-msvc": "2.0.0-next.
|
|
90
|
-
"@rrule-rust/lib-darwin-x64": "2.0.0-next.
|
|
91
|
-
"@rrule-rust/lib-linux-x64-gnu": "2.0.0-next.
|
|
92
|
-
"@rrule-rust/lib-darwin-arm64": "2.0.0-next.
|
|
93
|
-
"@rrule-rust/lib-android-arm64": "2.0.0-next.
|
|
94
|
-
"@rrule-rust/lib-linux-arm64-gnu": "2.0.0-next.
|
|
95
|
-
"@rrule-rust/lib-linux-arm64-musl": "2.0.0-next.
|
|
96
|
-
"@rrule-rust/lib-win32-arm64-msvc": "2.0.0-next.
|
|
97
|
-
"@rrule-rust/lib-linux-arm-gnueabihf": "2.0.0-next.
|
|
98
|
-
"@rrule-rust/lib-linux-
|
|
99
|
-
"@rrule-rust/lib-
|
|
100
|
-
"@rrule-rust/lib-
|
|
101
|
-
"@rrule-rust/lib-
|
|
102
|
-
"@rrule-rust/lib-
|
|
91
|
+
"@rrule-rust/lib-win32-x64-msvc": "2.0.0-next.6",
|
|
92
|
+
"@rrule-rust/lib-darwin-x64": "2.0.0-next.6",
|
|
93
|
+
"@rrule-rust/lib-linux-x64-gnu": "2.0.0-next.6",
|
|
94
|
+
"@rrule-rust/lib-darwin-arm64": "2.0.0-next.6",
|
|
95
|
+
"@rrule-rust/lib-android-arm64": "2.0.0-next.6",
|
|
96
|
+
"@rrule-rust/lib-linux-arm64-gnu": "2.0.0-next.6",
|
|
97
|
+
"@rrule-rust/lib-linux-arm64-musl": "2.0.0-next.6",
|
|
98
|
+
"@rrule-rust/lib-win32-arm64-msvc": "2.0.0-next.6",
|
|
99
|
+
"@rrule-rust/lib-linux-arm-gnueabihf": "2.0.0-next.6",
|
|
100
|
+
"@rrule-rust/lib-linux-arm-musleabihf": "2.0.0-next.6",
|
|
101
|
+
"@rrule-rust/lib-linux-x64-musl": "2.0.0-next.6",
|
|
102
|
+
"@rrule-rust/lib-freebsd-x64": "2.0.0-next.6",
|
|
103
|
+
"@rrule-rust/lib-win32-ia32-msvc": "2.0.0-next.6",
|
|
104
|
+
"@rrule-rust/lib-android-arm-eabi": "2.0.0-next.6",
|
|
105
|
+
"@rrule-rust/lib-darwin-universal": "2.0.0-next.6",
|
|
106
|
+
"@rrule-rust/lib-linux-riscv64-gnu": "2.0.0-next.6"
|
|
103
107
|
}
|
|
104
108
|
}
|
package/.eslintrc.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
extends: [
|
|
4
|
-
'eslint:recommended',
|
|
5
|
-
'plugin:@typescript-eslint/recommended',
|
|
6
|
-
'plugin:prettier/recommended',
|
|
7
|
-
'plugin:import/recommended',
|
|
8
|
-
'plugin:import/typescript',
|
|
9
|
-
'plugin:eslint-comments/recommended',
|
|
10
|
-
],
|
|
11
|
-
plugins: ['@typescript-eslint'],
|
|
12
|
-
ignorePatterns: ['node_modules', '/target', '/index.d.ts', '/index.js'],
|
|
13
|
-
env: {
|
|
14
|
-
node: true,
|
|
15
|
-
},
|
|
16
|
-
overrides: [
|
|
17
|
-
{
|
|
18
|
-
files: ['*.ts'],
|
|
19
|
-
extends: [
|
|
20
|
-
'eslint:recommended',
|
|
21
|
-
'plugin:@typescript-eslint/recommended',
|
|
22
|
-
'plugin:prettier/recommended',
|
|
23
|
-
'plugin:import/recommended',
|
|
24
|
-
'plugin:import/typescript',
|
|
25
|
-
],
|
|
26
|
-
parserOptions: {
|
|
27
|
-
project: ['tsconfig.eslint.json'],
|
|
28
|
-
},
|
|
29
|
-
rules: {
|
|
30
|
-
'@typescript-eslint/interface-name-prefix': 'off',
|
|
31
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
32
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
33
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
34
|
-
'@typescript-eslint/ban-ts-comment': 'off',
|
|
35
|
-
'import/no-cycle': 'error',
|
|
36
|
-
'import/no-unresolved': 'error',
|
|
37
|
-
'@typescript-eslint/no-for-in-array': 'error',
|
|
38
|
-
'no-implied-eval': 'off',
|
|
39
|
-
'@typescript-eslint/no-implied-eval': 'error',
|
|
40
|
-
'@typescript-eslint/no-misused-promises': 'error',
|
|
41
|
-
'require-await': 'off',
|
|
42
|
-
'@typescript-eslint/require-await': 'error',
|
|
43
|
-
'@typescript-eslint/restrict-plus-operands': 'error',
|
|
44
|
-
'@typescript-eslint/unbound-method': 'error',
|
|
45
|
-
'import/no-default-export': 'error',
|
|
46
|
-
'eslint-comments/require-description': 'error',
|
|
47
|
-
'eslint-comments/disable-enable-pair': 'off',
|
|
48
|
-
'eslint-comments/no-unlimited-disable': 'off',
|
|
49
|
-
},
|
|
50
|
-
settings: {
|
|
51
|
-
'import/parsers': {
|
|
52
|
-
'@typescript-eslint/parser': ['.ts'],
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
reportUnusedDisableDirectives: true,
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
};
|
package/.prettierrc
DELETED
package/.releaserc
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins": [
|
|
3
|
-
[
|
|
4
|
-
"@semantic-release/commit-analyzer",
|
|
5
|
-
{
|
|
6
|
-
"preset": "angular",
|
|
7
|
-
"releaseRules": [
|
|
8
|
-
{ "type": "docs", "release": "patch" },
|
|
9
|
-
{ "type": "perf", "release": "patch" },
|
|
10
|
-
{ "type": "revert", "release": "patch" }
|
|
11
|
-
]
|
|
12
|
-
}
|
|
13
|
-
],
|
|
14
|
-
[
|
|
15
|
-
"@semantic-release/release-notes-generator",
|
|
16
|
-
{
|
|
17
|
-
"parserOpts": {
|
|
18
|
-
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
|
|
19
|
-
},
|
|
20
|
-
"preset": "conventionalcommits",
|
|
21
|
-
"presetConfig": {
|
|
22
|
-
"types": [
|
|
23
|
-
{ "type": "build", "section": "Build System", "hidden": false },
|
|
24
|
-
{ "type": "chore", "section": "Build System", "hidden": false },
|
|
25
|
-
{ "type": "chore", "scope": "merge", "section": "Build System", "hidden": true },
|
|
26
|
-
{ "type": "ci", "section": "Continuous Integration", "hidden": false },
|
|
27
|
-
{ "type": "docs", "section": "Documentation", "hidden": false },
|
|
28
|
-
{ "type": "feat", "section": "Features", "hidden": false },
|
|
29
|
-
{ "type": "fix", "section": "Bug Fixes", "hidden": false },
|
|
30
|
-
{ "type": "perf", "section": "Performance Improvements", "hidden": false },
|
|
31
|
-
{ "type": "refactor", "section": "Code Refactoring", "hidden": false },
|
|
32
|
-
{ "type": "revert", "section": "Reverted Changes", "hidden": false },
|
|
33
|
-
{ "type": "style", "section": "Styles", "hidden": false },
|
|
34
|
-
{ "type": "test", "section": "Tests", "hidden": false }
|
|
35
|
-
]
|
|
36
|
-
},
|
|
37
|
-
"writerOpts": {
|
|
38
|
-
"commitsSort": ["subject", "scope"]
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
"@semantic-release/npm",
|
|
43
|
-
"@semantic-release/git",
|
|
44
|
-
"@semantic-release/github"
|
|
45
|
-
],
|
|
46
|
-
"branches": ["+([0-9])?(.{+([0-9]),x}).x", "master", {"name": "next", "prerelease": true}]
|
|
47
|
-
}
|
package/.yarnrc.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
nodeLinker: node-modules
|
package/Cargo.toml
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
edition = "2021"
|
|
3
|
-
name = "rrule-rust"
|
|
4
|
-
version = "0.0.0"
|
|
5
|
-
|
|
6
|
-
[lib]
|
|
7
|
-
crate-type = ["cdylib"]
|
|
8
|
-
|
|
9
|
-
[dependencies]
|
|
10
|
-
chrono = "0.4.24"
|
|
11
|
-
chrono-tz = "0.8.5"
|
|
12
|
-
# Default enable napi5 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
|
13
|
-
napi = { version = "2.11.1", default-features = false, features = ["napi5"] }
|
|
14
|
-
napi-derive = "2.11.0"
|
|
15
|
-
replace_with = "0.1.7"
|
|
16
|
-
rrule = { version = "0.12.0", features = ["exrule"] }
|
|
17
|
-
|
|
18
|
-
[build-dependencies]
|
|
19
|
-
napi-build = "2.0.1"
|
|
20
|
-
|
|
21
|
-
[profile.release]
|
|
22
|
-
lto = true
|
package/benchmark/.gitignore
DELETED
package/benchmark/index.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import b from 'benny';
|
|
2
|
-
import * as node from 'rrule';
|
|
3
|
-
import * as rust from '../';
|
|
4
|
-
|
|
5
|
-
b.suite(
|
|
6
|
-
'UTC TZ',
|
|
7
|
-
b.add('rrule-rust', () => {
|
|
8
|
-
const rrule = new rust.RRule(rust.Frequency.Daily)
|
|
9
|
-
.setCount(30)
|
|
10
|
-
.setInterval(1);
|
|
11
|
-
const set = new rust.RRuleSet(
|
|
12
|
-
new rust.RRuleDateTime(new Date(1679428740000), 'UTC'),
|
|
13
|
-
).addRrule(rrule);
|
|
14
|
-
|
|
15
|
-
set.all();
|
|
16
|
-
}),
|
|
17
|
-
b.add('rrule', () => {
|
|
18
|
-
const rrule = new node.RRule({
|
|
19
|
-
freq: node.RRule.DAILY,
|
|
20
|
-
dtstart: new Date(Date.UTC(2023, 2, 21, 23, 59, 0)),
|
|
21
|
-
tzid: 'UTC',
|
|
22
|
-
count: 30,
|
|
23
|
-
interval: 1,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
rrule.all();
|
|
27
|
-
}),
|
|
28
|
-
|
|
29
|
-
b.cycle(),
|
|
30
|
-
b.complete(),
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
b.suite(
|
|
34
|
-
'Other TZ',
|
|
35
|
-
b.add('rrule-rust', () => {
|
|
36
|
-
const rrule = new rust.RRule(rust.Frequency.Daily)
|
|
37
|
-
.setCount(30)
|
|
38
|
-
.setInterval(1);
|
|
39
|
-
const set = new rust.RRuleSet(
|
|
40
|
-
new rust.RRuleDateTime(new Date(1679428740000), 'Pacific/Kiritimati'),
|
|
41
|
-
).addRrule(rrule);
|
|
42
|
-
|
|
43
|
-
set.all();
|
|
44
|
-
}),
|
|
45
|
-
b.add('rrule', () => {
|
|
46
|
-
const rrule = new node.RRule({
|
|
47
|
-
freq: node.RRule.DAILY,
|
|
48
|
-
dtstart: new Date(Date.UTC(2023, 2, 21, 23, 59, 0)),
|
|
49
|
-
tzid: 'Pacific/Kiritimati',
|
|
50
|
-
count: 30,
|
|
51
|
-
interval: 1,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
rrule.all();
|
|
55
|
-
}),
|
|
56
|
-
|
|
57
|
-
b.cycle(),
|
|
58
|
-
b.complete(),
|
|
59
|
-
);
|
package/build.rs
DELETED
package/jest.config.ts
DELETED
package/src/js/frequency.rs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
use napi_derive::napi;
|
|
2
|
-
|
|
3
|
-
#[napi(js_name = "Frequency")]
|
|
4
|
-
pub enum Frequency {
|
|
5
|
-
Yearly,
|
|
6
|
-
Monthly,
|
|
7
|
-
Weekly,
|
|
8
|
-
Daily,
|
|
9
|
-
Hourly,
|
|
10
|
-
Minutely,
|
|
11
|
-
Secondly,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
impl From<rrule::Frequency> for Frequency {
|
|
15
|
-
fn from(freq: rrule::Frequency) -> Self {
|
|
16
|
-
match freq {
|
|
17
|
-
rrule::Frequency::Daily => Frequency::Daily,
|
|
18
|
-
rrule::Frequency::Hourly => Frequency::Hourly,
|
|
19
|
-
rrule::Frequency::Minutely => Frequency::Minutely,
|
|
20
|
-
rrule::Frequency::Monthly => Frequency::Monthly,
|
|
21
|
-
rrule::Frequency::Secondly => Frequency::Secondly,
|
|
22
|
-
rrule::Frequency::Weekly => Frequency::Weekly,
|
|
23
|
-
rrule::Frequency::Yearly => Frequency::Yearly,
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
impl Into<rrule::Frequency> for Frequency {
|
|
29
|
-
fn into(self) -> rrule::Frequency {
|
|
30
|
-
match self {
|
|
31
|
-
Frequency::Daily => rrule::Frequency::Daily,
|
|
32
|
-
Frequency::Hourly => rrule::Frequency::Hourly,
|
|
33
|
-
Frequency::Minutely => rrule::Frequency::Minutely,
|
|
34
|
-
Frequency::Monthly => rrule::Frequency::Monthly,
|
|
35
|
-
Frequency::Secondly => rrule::Frequency::Secondly,
|
|
36
|
-
Frequency::Weekly => rrule::Frequency::Weekly,
|
|
37
|
-
Frequency::Yearly => rrule::Frequency::Yearly,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/js/month.rs
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
use napi_derive::napi;
|
|
2
|
-
|
|
3
|
-
#[napi(js_name = "Month")]
|
|
4
|
-
pub enum Month {
|
|
5
|
-
January,
|
|
6
|
-
February,
|
|
7
|
-
March,
|
|
8
|
-
April,
|
|
9
|
-
May,
|
|
10
|
-
June,
|
|
11
|
-
July,
|
|
12
|
-
August,
|
|
13
|
-
September,
|
|
14
|
-
October,
|
|
15
|
-
November,
|
|
16
|
-
December,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
impl From<&u8> for Month {
|
|
20
|
-
fn from(month: &u8) -> Self {
|
|
21
|
-
match month {
|
|
22
|
-
0 => Month::January,
|
|
23
|
-
1 => Month::February,
|
|
24
|
-
2 => Month::March,
|
|
25
|
-
3 => Month::April,
|
|
26
|
-
4 => Month::May,
|
|
27
|
-
5 => Month::June,
|
|
28
|
-
6 => Month::July,
|
|
29
|
-
7 => Month::August,
|
|
30
|
-
8 => Month::September,
|
|
31
|
-
9 => Month::October,
|
|
32
|
-
10 => Month::November,
|
|
33
|
-
11 => Month::December,
|
|
34
|
-
_ => panic!("Unknown month index: {}", month),
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
impl Into<chrono::Month> for Month {
|
|
40
|
-
fn into(self) -> chrono::Month {
|
|
41
|
-
match self {
|
|
42
|
-
Month::January => chrono::Month::January,
|
|
43
|
-
Month::February => chrono::Month::February,
|
|
44
|
-
Month::March => chrono::Month::March,
|
|
45
|
-
Month::April => chrono::Month::April,
|
|
46
|
-
Month::May => chrono::Month::May,
|
|
47
|
-
Month::June => chrono::Month::June,
|
|
48
|
-
Month::July => chrono::Month::July,
|
|
49
|
-
Month::August => chrono::Month::August,
|
|
50
|
-
Month::September => chrono::Month::September,
|
|
51
|
-
Month::October => chrono::Month::October,
|
|
52
|
-
Month::November => chrono::Month::November,
|
|
53
|
-
Month::December => chrono::Month::December,
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
package/src/js/n_weekday.rs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
use super::weekday::Weekday;
|
|
2
|
-
use napi_derive::napi;
|
|
3
|
-
|
|
4
|
-
#[napi(object, js_name = "NWeekday")]
|
|
5
|
-
pub struct NWeekday {
|
|
6
|
-
/// If set, this represents the nth occurrence of the weekday.
|
|
7
|
-
/// Otherwise it represents every occurrence of the weekday.
|
|
8
|
-
///
|
|
9
|
-
/// A negative value represents nth occurrence from the end.
|
|
10
|
-
pub n: Option<i16>,
|
|
11
|
-
pub weekday: Weekday,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
impl From<rrule::NWeekday> for NWeekday {
|
|
15
|
-
fn from(nday: rrule::NWeekday) -> Self {
|
|
16
|
-
match nday {
|
|
17
|
-
rrule::NWeekday::Every(weekday) => NWeekday {
|
|
18
|
-
n: None,
|
|
19
|
-
weekday: Weekday::from(weekday),
|
|
20
|
-
},
|
|
21
|
-
rrule::NWeekday::Nth(n, weekday) => NWeekday {
|
|
22
|
-
n: Some(n),
|
|
23
|
-
weekday: weekday.into(),
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
impl Into<rrule::NWeekday> for NWeekday {
|
|
30
|
-
fn into(self) -> rrule::NWeekday {
|
|
31
|
-
match self.n {
|
|
32
|
-
Some(n) => rrule::NWeekday::Nth(n, self.weekday.into()),
|
|
33
|
-
None => rrule::NWeekday::Every(self.weekday.into()),
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/js/rrule.rs
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
use super::{Frequency, Month, NWeekday, RRuleDateTime, Weekday};
|
|
2
|
-
use chrono::DateTime;
|
|
3
|
-
use napi::{bindgen_prelude::Array, Either, Env};
|
|
4
|
-
use napi_derive::napi;
|
|
5
|
-
use replace_with::replace_with_or_abort;
|
|
6
|
-
|
|
7
|
-
#[napi(js_name = "RRule")]
|
|
8
|
-
pub struct RRule {
|
|
9
|
-
rrule: rrule::RRule<rrule::Unvalidated>,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
#[napi]
|
|
13
|
-
impl RRule {
|
|
14
|
-
#[napi(constructor)]
|
|
15
|
-
pub fn new(frequency: Frequency) -> Self {
|
|
16
|
-
let rrule = rrule::RRule::new(frequency.into());
|
|
17
|
-
|
|
18
|
-
RRule { rrule }
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
#[napi(factory, ts_return_type = "RRule")]
|
|
22
|
-
pub fn parse(str: String) -> napi::Result<Self> {
|
|
23
|
-
let rrule: rrule::RRule<rrule::Unvalidated> = str
|
|
24
|
-
.parse()
|
|
25
|
-
.map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
|
|
26
|
-
|
|
27
|
-
Ok(RRule { rrule })
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
#[napi(getter)]
|
|
31
|
-
pub fn frequency(&self) -> napi::Result<Frequency> {
|
|
32
|
-
Ok(Frequency::from(self.rrule.get_freq()))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
#[napi(getter)]
|
|
36
|
-
pub fn interval(&self) -> napi::Result<u16> {
|
|
37
|
-
Ok(self.rrule.get_interval())
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
#[napi(getter)]
|
|
41
|
-
pub fn count(&self) -> napi::Result<Option<u32>> {
|
|
42
|
-
Ok(self.rrule.get_count())
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
#[napi(getter, ts_return_type = "NWeekday[]")]
|
|
46
|
-
pub fn by_weekday(&self) -> Vec<NWeekday> {
|
|
47
|
-
return self
|
|
48
|
-
.rrule
|
|
49
|
-
.get_by_weekday()
|
|
50
|
-
.iter()
|
|
51
|
-
.map(|nday| NWeekday::from(*nday))
|
|
52
|
-
.collect();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
#[napi(getter)]
|
|
56
|
-
pub fn by_hour(&self) -> napi::Result<Vec<u8>> {
|
|
57
|
-
Ok(self.rrule.get_by_hour().to_vec())
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
#[napi(getter)]
|
|
61
|
-
pub fn by_minute(&self) -> napi::Result<Vec<u8>> {
|
|
62
|
-
Ok(self.rrule.get_by_minute().to_vec())
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
#[napi(getter)]
|
|
66
|
-
pub fn by_second(&self) -> napi::Result<Vec<u8>> {
|
|
67
|
-
Ok(self.rrule.get_by_second().to_vec())
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
#[napi(getter)]
|
|
71
|
-
pub fn by_monthday(&self) -> napi::Result<Vec<i8>> {
|
|
72
|
-
Ok(self.rrule.get_by_month_day().to_vec())
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
#[napi(getter)]
|
|
76
|
-
pub fn by_setpos(&self) -> napi::Result<Vec<i32>> {
|
|
77
|
-
Ok(self.rrule.get_by_set_pos().to_vec())
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
#[napi(getter, ts_return_type = "Month[]")]
|
|
81
|
-
pub fn by_month(&self, env: Env) -> napi::Result<Array> {
|
|
82
|
-
let months = self.rrule.get_by_month();
|
|
83
|
-
let mut arr = env.create_array(0)?;
|
|
84
|
-
|
|
85
|
-
for month in months.iter() {
|
|
86
|
-
arr.insert(Month::from(month))?;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
Ok(arr)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
#[napi(getter)]
|
|
93
|
-
pub fn by_weekno(&self) -> napi::Result<Vec<i8>> {
|
|
94
|
-
Ok(self.rrule.get_by_week_no().to_vec())
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
#[napi(getter)]
|
|
98
|
-
pub fn by_yearday(&self) -> napi::Result<Vec<i16>> {
|
|
99
|
-
Ok(self.rrule.get_by_year_day().to_vec())
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
#[napi(getter)]
|
|
103
|
-
pub fn weekstart(&self) -> napi::Result<Weekday> {
|
|
104
|
-
Ok(Weekday::from(self.rrule.get_week_start()))
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
#[napi(getter)]
|
|
108
|
-
pub fn until(&self) -> napi::Result<Option<RRuleDateTime>> {
|
|
109
|
-
Ok(match self.rrule.get_until() {
|
|
110
|
-
Some(until) => Some(RRuleDateTime::new_with_date_time(until.clone())),
|
|
111
|
-
None => None,
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
#[napi]
|
|
116
|
-
pub fn to_string(&self) -> napi::Result<String> {
|
|
117
|
-
Ok(self.rrule.to_string())
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
#[napi]
|
|
121
|
-
pub fn set_interval(&mut self, interval: u16) -> napi::Result<&Self> {
|
|
122
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.interval(interval));
|
|
123
|
-
|
|
124
|
-
Ok(self)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
#[napi]
|
|
128
|
-
pub fn set_count(&mut self, count: u32) -> napi::Result<&Self> {
|
|
129
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.count(count));
|
|
130
|
-
|
|
131
|
-
Ok(self)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
#[napi]
|
|
135
|
-
pub fn set_by_weekday(
|
|
136
|
-
&mut self,
|
|
137
|
-
#[napi(ts_arg_type = "ReadonlyArray<NWeekday | Weekday>")] weekdays: Vec<
|
|
138
|
-
Either<NWeekday, Weekday>,
|
|
139
|
-
>,
|
|
140
|
-
) -> napi::Result<&Self> {
|
|
141
|
-
let by_weekday = weekdays
|
|
142
|
-
.into_iter()
|
|
143
|
-
.map(|weekday| match weekday {
|
|
144
|
-
Either::A(nday) => nday.into(),
|
|
145
|
-
Either::B(weekday) => rrule::NWeekday::Every(weekday.into()),
|
|
146
|
-
})
|
|
147
|
-
.collect();
|
|
148
|
-
|
|
149
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_weekday(by_weekday));
|
|
150
|
-
|
|
151
|
-
Ok(self)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
#[napi]
|
|
155
|
-
pub fn set_by_hour(
|
|
156
|
-
&mut self,
|
|
157
|
-
#[napi(ts_arg_type = "ReadonlyArray<number>")] hours: Vec<u8>,
|
|
158
|
-
) -> napi::Result<&Self> {
|
|
159
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_hour(hours));
|
|
160
|
-
|
|
161
|
-
Ok(self)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
#[napi]
|
|
165
|
-
pub fn set_by_minute(
|
|
166
|
-
&mut self,
|
|
167
|
-
#[napi(ts_arg_type = "ReadonlyArray<number>")] minutes: Vec<u8>,
|
|
168
|
-
) -> napi::Result<&Self> {
|
|
169
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_minute(minutes));
|
|
170
|
-
|
|
171
|
-
Ok(self)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
#[napi]
|
|
175
|
-
pub fn set_by_second(
|
|
176
|
-
&mut self,
|
|
177
|
-
#[napi(ts_arg_type = "ReadonlyArray<number>")] seconds: Vec<u8>,
|
|
178
|
-
) -> napi::Result<&Self> {
|
|
179
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_second(seconds));
|
|
180
|
-
|
|
181
|
-
Ok(self)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
#[napi]
|
|
185
|
-
pub fn set_by_monthday(
|
|
186
|
-
&mut self,
|
|
187
|
-
#[napi(ts_arg_type = "ReadonlyArray<number>")] days: Vec<i8>,
|
|
188
|
-
) -> napi::Result<&Self> {
|
|
189
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_month_day(days));
|
|
190
|
-
|
|
191
|
-
Ok(self)
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
#[napi]
|
|
195
|
-
pub fn set_by_setpos(
|
|
196
|
-
&mut self,
|
|
197
|
-
#[napi(ts_arg_type = "ReadonlyArray<number>")] poses: Vec<i32>,
|
|
198
|
-
) -> napi::Result<&Self> {
|
|
199
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_set_pos(poses));
|
|
200
|
-
|
|
201
|
-
Ok(self)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
#[napi]
|
|
205
|
-
pub fn set_by_month(
|
|
206
|
-
&mut self,
|
|
207
|
-
#[napi(ts_arg_type = "ReadonlyArray<Month>")] months: Array,
|
|
208
|
-
) -> napi::Result<&Self> {
|
|
209
|
-
let mut vec: Vec<chrono::Month> = Vec::new();
|
|
210
|
-
|
|
211
|
-
for i in 0..months.len() {
|
|
212
|
-
let month: Month = months.get(i).unwrap().unwrap();
|
|
213
|
-
|
|
214
|
-
vec.push(month.into());
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_month(&vec));
|
|
218
|
-
|
|
219
|
-
Ok(self)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
#[napi]
|
|
223
|
-
pub fn set_by_weekno(
|
|
224
|
-
&mut self,
|
|
225
|
-
#[napi(ts_arg_type = "ReadonlyArray<number>")] week_numbers: Vec<i8>,
|
|
226
|
-
) -> napi::Result<&Self> {
|
|
227
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_week_no(week_numbers));
|
|
228
|
-
|
|
229
|
-
Ok(self)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
#[napi]
|
|
233
|
-
pub fn set_by_yearday(
|
|
234
|
-
&mut self,
|
|
235
|
-
#[napi(ts_arg_type = "ReadonlyArray<number>")] days: Vec<i16>,
|
|
236
|
-
) -> napi::Result<&Self> {
|
|
237
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.by_year_day(days));
|
|
238
|
-
|
|
239
|
-
Ok(self)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
#[napi]
|
|
243
|
-
pub fn set_weekstart(&mut self, day: Weekday) -> napi::Result<&Self> {
|
|
244
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.week_start(day.into()));
|
|
245
|
-
|
|
246
|
-
Ok(self)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
#[napi]
|
|
250
|
-
pub fn set_until(
|
|
251
|
-
&mut self,
|
|
252
|
-
date_time: napi::Either<&RRuleDateTime, napi::JsDate>,
|
|
253
|
-
) -> napi::Result<&Self> {
|
|
254
|
-
let date_time = RRuleDateTime::from(date_time);
|
|
255
|
-
replace_with_or_abort(&mut self.rrule, |self_| self_.until(date_time.into()));
|
|
256
|
-
|
|
257
|
-
Ok(self)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
pub fn validate(&self, dt_start: DateTime<rrule::Tz>) -> napi::Result<rrule::RRule> {
|
|
261
|
-
return Ok(
|
|
262
|
-
self
|
|
263
|
-
.rrule
|
|
264
|
-
.clone()
|
|
265
|
-
.validate(dt_start)
|
|
266
|
-
.map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?,
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
impl From<rrule::RRule<rrule::Unvalidated>> for RRule {
|
|
272
|
-
fn from(rrule: rrule::RRule<rrule::Unvalidated>) -> Self {
|
|
273
|
-
Self { rrule }
|
|
274
|
-
}
|
|
275
|
-
}
|
package/src/js/rrule_datetime.rs
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
use super::RRuleTimezone;
|
|
2
|
-
use chrono::DateTime;
|
|
3
|
-
use chrono::Datelike;
|
|
4
|
-
use chrono::TimeZone;
|
|
5
|
-
use chrono::Timelike;
|
|
6
|
-
use napi::bindgen_prelude::*;
|
|
7
|
-
use napi_derive::napi;
|
|
8
|
-
use std::str::FromStr;
|
|
9
|
-
|
|
10
|
-
#[napi(js_name = "RRuleDateTime")]
|
|
11
|
-
pub struct RRuleDateTime {
|
|
12
|
-
date_time: chrono::DateTime<rrule::Tz>,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
#[napi]
|
|
16
|
-
impl RRuleDateTime {
|
|
17
|
-
#[napi(constructor)]
|
|
18
|
-
pub fn new_with_js_date(
|
|
19
|
-
date: napi::Either<napi::JsDate, f64>,
|
|
20
|
-
timezone: Option<String>,
|
|
21
|
-
) -> napi::Result<Self> {
|
|
22
|
-
let timestamp = match date {
|
|
23
|
-
Either::A(date) => date.value_of(),
|
|
24
|
-
Either::B(date) => Ok(date),
|
|
25
|
-
}?;
|
|
26
|
-
|
|
27
|
-
let mut date_time = rrule::Tz::LOCAL.timestamp_nanos((timestamp * 1_000_000f64) as i64);
|
|
28
|
-
if let Some(timezone) = timezone {
|
|
29
|
-
let tz: rrule::Tz = RRuleTimezone::from_str(&timezone)?.into();
|
|
30
|
-
|
|
31
|
-
date_time = date_time.with_timezone(&tz);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Ok(RRuleDateTime::new_with_date_time(date_time))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
pub fn new_with_date_time(date_time: DateTime<rrule::Tz>) -> Self {
|
|
38
|
-
RRuleDateTime { date_time }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
#[napi(getter)]
|
|
42
|
-
pub fn timestamp(&self) -> i64 {
|
|
43
|
-
self.date_time.timestamp_millis()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
#[napi(getter)]
|
|
47
|
-
pub fn timezone(&self) -> RRuleTimezone {
|
|
48
|
-
RRuleTimezone::new_with_tz(self.date_time.timezone())
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
#[napi(getter)]
|
|
52
|
-
pub fn day(&self) -> u32 {
|
|
53
|
-
self.date_time.day()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
#[napi(getter)]
|
|
57
|
-
pub fn month(&self) -> u32 {
|
|
58
|
-
self.date_time.month()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
#[napi(getter)]
|
|
62
|
-
pub fn year(&self) -> i32 {
|
|
63
|
-
self.date_time.year()
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
#[napi(getter)]
|
|
67
|
-
pub fn hour(&self) -> u32 {
|
|
68
|
-
self.date_time.hour()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
#[napi(getter)]
|
|
72
|
-
pub fn minute(&self) -> u32 {
|
|
73
|
-
self.date_time.minute()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
#[napi(getter)]
|
|
77
|
-
pub fn second(&self) -> u32 {
|
|
78
|
-
self.date_time.second()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
#[napi(getter)]
|
|
82
|
-
pub fn millisecond(&self) -> u32 {
|
|
83
|
-
let nanoseconds = self.date_time.nanosecond();
|
|
84
|
-
nanoseconds / 1_000_000
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
#[napi(getter)]
|
|
88
|
-
pub fn to_string(&self) -> String {
|
|
89
|
-
self.date_time.to_string()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
#[napi(ts_return_type = "Date")]
|
|
93
|
-
pub fn to_date(&self, env: Env) -> napi::Result<napi::JsDate> {
|
|
94
|
-
env.create_date(self.date_time.timestamp_millis() as f64)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
#[napi(ts_return_type = "Date")]
|
|
98
|
-
pub fn to_utc_date(&self, env: Env) -> napi::Result<napi::JsDate> {
|
|
99
|
-
env.create_date(self.date_time.naive_utc().and_utc().timestamp_millis() as f64)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
impl From<DateTime<rrule::Tz>> for RRuleDateTime {
|
|
104
|
-
fn from(date_time: DateTime<rrule::Tz>) -> Self {
|
|
105
|
-
RRuleDateTime::new_with_date_time(date_time)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
impl Into<DateTime<rrule::Tz>> for RRuleDateTime {
|
|
110
|
-
fn into(self) -> DateTime<rrule::Tz> {
|
|
111
|
-
self.date_time
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
impl From<napi::JsDate> for RRuleDateTime {
|
|
116
|
-
fn from(date: napi::JsDate) -> Self {
|
|
117
|
-
RRuleDateTime::new_with_js_date(napi::Either::A(date), None).unwrap()
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
impl From<napi::Either<&RRuleDateTime, napi::JsDate>> for RRuleDateTime {
|
|
122
|
-
fn from(date: napi::Either<&RRuleDateTime, napi::JsDate>) -> Self {
|
|
123
|
-
match date {
|
|
124
|
-
Either::A(date) => RRuleDateTime::new_with_date_time(date.date_time),
|
|
125
|
-
Either::B(date) => RRuleDateTime::new_with_js_date(napi::Either::A(date), None).unwrap(),
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
package/src/js/rrule_set.rs
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
use super::{RRule, RRuleDateTime};
|
|
2
|
-
use chrono::DateTime;
|
|
3
|
-
use napi::{
|
|
4
|
-
bindgen_prelude::{Reference, SharedReference},
|
|
5
|
-
iterator::Generator,
|
|
6
|
-
Env,
|
|
7
|
-
};
|
|
8
|
-
use napi_derive::napi;
|
|
9
|
-
use replace_with::replace_with_or_abort;
|
|
10
|
-
|
|
11
|
-
#[napi(js_name = "RRuleSet")]
|
|
12
|
-
pub struct RRuleSet {
|
|
13
|
-
rrule_set: rrule::RRuleSet,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
#[napi]
|
|
17
|
-
impl RRuleSet {
|
|
18
|
-
#[napi(constructor)]
|
|
19
|
-
pub fn new(dtstart: napi::Either<&RRuleDateTime, napi::JsDate>) -> napi::Result<Self> {
|
|
20
|
-
let rrule_set = rrule::RRuleSet::new(RRuleDateTime::from(dtstart).into());
|
|
21
|
-
|
|
22
|
-
Ok(RRuleSet { rrule_set })
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
#[napi(factory, ts_return_type = "RRuleSet")]
|
|
26
|
-
pub fn parse(str: String) -> napi::Result<Self> {
|
|
27
|
-
let rrule_set: rrule::RRuleSet = str
|
|
28
|
-
.parse()
|
|
29
|
-
.map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
|
|
30
|
-
|
|
31
|
-
Ok(RRuleSet { rrule_set })
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
#[napi]
|
|
35
|
-
pub fn to_string(&self) -> napi::Result<String> {
|
|
36
|
-
Ok(self.rrule_set.to_string())
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
#[napi]
|
|
40
|
-
pub fn add_rrule(&mut self, js_rrule: &RRule) -> napi::Result<&Self> {
|
|
41
|
-
let dt_start = self.rrule_set.get_dt_start().clone();
|
|
42
|
-
let rrule = js_rrule.validate(dt_start)?;
|
|
43
|
-
|
|
44
|
-
replace_with_or_abort(&mut self.rrule_set, |self_| self_.rrule(rrule));
|
|
45
|
-
|
|
46
|
-
Ok(self)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#[napi]
|
|
50
|
-
pub fn add_exrule(&mut self, js_rrule: &RRule) -> napi::Result<&Self> {
|
|
51
|
-
let rrule = js_rrule.validate(*self.rrule_set.get_dt_start())?;
|
|
52
|
-
|
|
53
|
-
replace_with_or_abort(&mut self.rrule_set, |self_| self_.exrule(rrule));
|
|
54
|
-
|
|
55
|
-
Ok(self)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
#[napi]
|
|
59
|
-
pub fn add_exdate(
|
|
60
|
-
&mut self,
|
|
61
|
-
date_time: napi::Either<&RRuleDateTime, napi::JsDate>,
|
|
62
|
-
) -> napi::Result<&Self> {
|
|
63
|
-
replace_with_or_abort(&mut self.rrule_set, |self_| {
|
|
64
|
-
self_.exdate(RRuleDateTime::from(date_time).into())
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
Ok(self)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
#[napi]
|
|
71
|
-
pub fn add_rdate(
|
|
72
|
-
&mut self,
|
|
73
|
-
date_time: napi::Either<&RRuleDateTime, napi::JsDate>,
|
|
74
|
-
) -> napi::Result<&Self> {
|
|
75
|
-
replace_with_or_abort(&mut self.rrule_set, |self_| {
|
|
76
|
-
self_.rdate(RRuleDateTime::from(date_time).into())
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
Ok(self)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#[napi(getter)]
|
|
83
|
-
pub fn dtstart(&self) -> RRuleDateTime {
|
|
84
|
-
RRuleDateTime::new_with_date_time(self.rrule_set.get_dt_start().clone())
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
#[napi]
|
|
88
|
-
pub fn get_rrules(&self) -> Vec<RRule> {
|
|
89
|
-
return self
|
|
90
|
-
.rrule_set
|
|
91
|
-
.get_rrule()
|
|
92
|
-
.iter()
|
|
93
|
-
.map(|rrule| RRule::from(to_unvalidated(rrule)))
|
|
94
|
-
.collect();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
#[napi]
|
|
98
|
-
pub fn get_exrules(&self) -> Vec<RRule> {
|
|
99
|
-
return self
|
|
100
|
-
.rrule_set
|
|
101
|
-
.get_exrule()
|
|
102
|
-
.iter()
|
|
103
|
-
.map(|rrule| RRule::from(to_unvalidated(rrule)))
|
|
104
|
-
.collect();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
#[napi]
|
|
108
|
-
pub fn get_exdates(&self) -> Vec<RRuleDateTime> {
|
|
109
|
-
return self
|
|
110
|
-
.rrule_set
|
|
111
|
-
.get_exdate()
|
|
112
|
-
.iter()
|
|
113
|
-
.map(|date| RRuleDateTime::new_with_date_time(date.clone()))
|
|
114
|
-
.collect();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
#[napi]
|
|
118
|
-
pub fn get_rdates(&self) -> Vec<RRuleDateTime> {
|
|
119
|
-
return self
|
|
120
|
-
.rrule_set
|
|
121
|
-
.get_rdate()
|
|
122
|
-
.iter()
|
|
123
|
-
.map(|date| RRuleDateTime::new_with_date_time(date.clone()))
|
|
124
|
-
.collect();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
fn is_after(
|
|
128
|
-
&self,
|
|
129
|
-
timestamp: DateTime<rrule::Tz>,
|
|
130
|
-
after_timestamp: DateTime<rrule::Tz>,
|
|
131
|
-
inclusive: Option<bool>,
|
|
132
|
-
) -> bool {
|
|
133
|
-
let inclusive = inclusive.unwrap_or(false);
|
|
134
|
-
|
|
135
|
-
if inclusive && timestamp < after_timestamp {
|
|
136
|
-
return false;
|
|
137
|
-
} else if !inclusive && timestamp <= after_timestamp {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
true
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
fn is_before(
|
|
145
|
-
&self,
|
|
146
|
-
timestamp: DateTime<rrule::Tz>,
|
|
147
|
-
before_timestamp: DateTime<rrule::Tz>,
|
|
148
|
-
inclusive: Option<bool>,
|
|
149
|
-
) -> bool {
|
|
150
|
-
let inclusive = inclusive.unwrap_or(false);
|
|
151
|
-
|
|
152
|
-
if inclusive && timestamp > before_timestamp {
|
|
153
|
-
return false;
|
|
154
|
-
} else if !inclusive && timestamp >= before_timestamp {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
true
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
#[napi]
|
|
162
|
-
pub fn all(&self, limit: Option<u32>) -> Vec<RRuleDateTime> {
|
|
163
|
-
let iter = self.rrule_set.into_iter();
|
|
164
|
-
if let Some(limit) = limit {
|
|
165
|
-
return iter
|
|
166
|
-
.take(limit as usize)
|
|
167
|
-
.map(|date| RRuleDateTime::new_with_date_time(date))
|
|
168
|
-
.collect();
|
|
169
|
-
} else {
|
|
170
|
-
return iter
|
|
171
|
-
.map(|date| RRuleDateTime::new_with_date_time(date))
|
|
172
|
-
.collect();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
#[napi]
|
|
177
|
-
pub fn between(
|
|
178
|
-
&self,
|
|
179
|
-
after: napi::Either<&RRuleDateTime, napi::JsDate>,
|
|
180
|
-
before: napi::Either<&RRuleDateTime, napi::JsDate>,
|
|
181
|
-
inclusive: Option<bool>,
|
|
182
|
-
) -> napi::Result<Vec<RRuleDateTime>> {
|
|
183
|
-
let _after = RRuleDateTime::from(after).into();
|
|
184
|
-
let _before = RRuleDateTime::from(before).into();
|
|
185
|
-
return Ok(
|
|
186
|
-
self
|
|
187
|
-
.rrule_set
|
|
188
|
-
.into_iter()
|
|
189
|
-
.take_while(|date| {
|
|
190
|
-
let is_before = self.is_before(*date, _before, inclusive);
|
|
191
|
-
|
|
192
|
-
is_before
|
|
193
|
-
})
|
|
194
|
-
.filter(|date| {
|
|
195
|
-
let is_after = self.is_after(*date, _after, inclusive);
|
|
196
|
-
|
|
197
|
-
is_after
|
|
198
|
-
})
|
|
199
|
-
.map(|date| RRuleDateTime::new_with_date_time(date))
|
|
200
|
-
.collect::<Vec<_>>(),
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
#[napi]
|
|
205
|
-
pub fn occurrences(&self, this: Reference<RRuleSet>, env: Env) -> napi::Result<Occurrences> {
|
|
206
|
-
let iter = this.share_with(env, |set| Ok(set.rrule_set.into_iter()))?;
|
|
207
|
-
Ok(Occurrences { iter })
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
#[napi(iterator)]
|
|
212
|
-
pub struct Occurrences {
|
|
213
|
-
iter: SharedReference<RRuleSet, rrule::RRuleSetIter<'static>>,
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
#[napi]
|
|
217
|
-
impl Generator for Occurrences {
|
|
218
|
-
type Yield = RRuleDateTime;
|
|
219
|
-
type Next = ();
|
|
220
|
-
type Return = ();
|
|
221
|
-
|
|
222
|
-
fn next(&mut self, _next: Option<Self::Next>) -> Option<Self::Yield> {
|
|
223
|
-
self
|
|
224
|
-
.iter
|
|
225
|
-
.next()
|
|
226
|
-
.map(|date| RRuleDateTime::new_with_date_time(date))
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
fn to_unvalidated(rrule: &rrule::RRule) -> rrule::RRule<rrule::Unvalidated> {
|
|
231
|
-
let by_month = rrule
|
|
232
|
-
.get_by_month()
|
|
233
|
-
.iter()
|
|
234
|
-
.map(|m| chrono::Month::try_from(*m).unwrap())
|
|
235
|
-
.collect::<Vec<_>>();
|
|
236
|
-
let mut unvalidated = rrule::RRule::new(rrule.get_freq())
|
|
237
|
-
.interval(rrule.get_interval())
|
|
238
|
-
.week_start(rrule.get_week_start())
|
|
239
|
-
.by_set_pos(rrule.get_by_set_pos().to_vec())
|
|
240
|
-
.by_month(&by_month)
|
|
241
|
-
.by_month_day(rrule.get_by_month_day().to_vec())
|
|
242
|
-
.by_year_day(rrule.get_by_year_day().to_vec())
|
|
243
|
-
.by_week_no(rrule.get_by_week_no().to_vec())
|
|
244
|
-
.by_weekday(rrule.get_by_weekday().to_vec())
|
|
245
|
-
.by_hour(rrule.get_by_hour().to_vec())
|
|
246
|
-
.by_minute(rrule.get_by_minute().to_vec())
|
|
247
|
-
.by_second(rrule.get_by_second().to_vec());
|
|
248
|
-
|
|
249
|
-
if let Some(count) = rrule.get_count() {
|
|
250
|
-
unvalidated = unvalidated.count(count);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if let Some(until) = rrule.get_until() {
|
|
254
|
-
unvalidated = unvalidated.until(*until);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
unvalidated
|
|
258
|
-
}
|
package/src/js/rrule_timezone.rs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
use napi_derive::napi;
|
|
2
|
-
use std::str::FromStr;
|
|
3
|
-
|
|
4
|
-
#[derive(Debug)]
|
|
5
|
-
#[napi(js_name = "RRuleTimezone")]
|
|
6
|
-
pub struct RRuleTimezone {
|
|
7
|
-
tz: rrule::Tz,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
#[napi]
|
|
11
|
-
impl RRuleTimezone {
|
|
12
|
-
#[napi(constructor)]
|
|
13
|
-
pub fn new(tz: String) -> napi::Result<Self> {
|
|
14
|
-
Ok(tz.parse()?)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
pub fn new_with_tz(tz: rrule::Tz) -> Self {
|
|
18
|
-
RRuleTimezone { tz }
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The name of the timezone. If the timezone is local, it will return "Local".
|
|
23
|
-
*/
|
|
24
|
-
#[napi(getter)]
|
|
25
|
-
pub fn name(&self) -> String {
|
|
26
|
-
self.tz.name().to_string()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
#[napi(getter)]
|
|
30
|
-
pub fn is_local(&self) -> bool {
|
|
31
|
-
self.tz.is_local()
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
impl Into<rrule::Tz> for RRuleTimezone {
|
|
36
|
-
fn into(self) -> rrule::Tz {
|
|
37
|
-
self.tz
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
impl FromStr for RRuleTimezone {
|
|
42
|
-
type Err = napi::Error;
|
|
43
|
-
|
|
44
|
-
fn from_str(str: &str) -> Result<Self, Self::Err> {
|
|
45
|
-
str
|
|
46
|
-
.parse::<chrono_tz::Tz>()
|
|
47
|
-
.map(|tz| RRuleTimezone {
|
|
48
|
-
tz: rrule::Tz::Tz(tz),
|
|
49
|
-
})
|
|
50
|
-
.map_err(|err| napi::Error::new(napi::Status::GenericFailure, err.to_string()))
|
|
51
|
-
}
|
|
52
|
-
}
|
package/src/js/weekday.rs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
use napi_derive::napi;
|
|
2
|
-
|
|
3
|
-
#[napi(js_name = "Weekday")]
|
|
4
|
-
pub enum Weekday {
|
|
5
|
-
Monday,
|
|
6
|
-
Tuesday,
|
|
7
|
-
Wednesday,
|
|
8
|
-
Thursday,
|
|
9
|
-
Friday,
|
|
10
|
-
Saturday,
|
|
11
|
-
Sunday,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
impl From<rrule::Weekday> for Weekday {
|
|
15
|
-
fn from(weekday: rrule::Weekday) -> Self {
|
|
16
|
-
match weekday {
|
|
17
|
-
rrule::Weekday::Mon => Weekday::Monday,
|
|
18
|
-
rrule::Weekday::Tue => Weekday::Tuesday,
|
|
19
|
-
rrule::Weekday::Wed => Weekday::Wednesday,
|
|
20
|
-
rrule::Weekday::Thu => Weekday::Thursday,
|
|
21
|
-
rrule::Weekday::Fri => Weekday::Friday,
|
|
22
|
-
rrule::Weekday::Sat => Weekday::Saturday,
|
|
23
|
-
rrule::Weekday::Sun => Weekday::Sunday,
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
impl Into<rrule::Weekday> for Weekday {
|
|
29
|
-
fn into(self) -> rrule::Weekday {
|
|
30
|
-
match self {
|
|
31
|
-
Weekday::Monday => rrule::Weekday::Mon,
|
|
32
|
-
Weekday::Tuesday => rrule::Weekday::Tue,
|
|
33
|
-
Weekday::Wednesday => rrule::Weekday::Wed,
|
|
34
|
-
Weekday::Thursday => rrule::Weekday::Thu,
|
|
35
|
-
Weekday::Friday => rrule::Weekday::Fri,
|
|
36
|
-
Weekday::Saturday => rrule::Weekday::Sat,
|
|
37
|
-
Weekday::Sunday => rrule::Weekday::Sun,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/js.rs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
mod frequency;
|
|
2
|
-
mod month;
|
|
3
|
-
mod n_weekday;
|
|
4
|
-
mod rrule;
|
|
5
|
-
mod rrule_datetime;
|
|
6
|
-
mod rrule_set;
|
|
7
|
-
mod rrule_timezone;
|
|
8
|
-
mod weekday;
|
|
9
|
-
|
|
10
|
-
pub use frequency::Frequency;
|
|
11
|
-
pub use month::Month;
|
|
12
|
-
pub use n_weekday::NWeekday;
|
|
13
|
-
pub use rrule::RRule;
|
|
14
|
-
pub use rrule_datetime::RRuleDateTime;
|
|
15
|
-
pub use rrule_set::RRuleSet;
|
|
16
|
-
pub use rrule_timezone::RRuleTimezone;
|
|
17
|
-
pub use weekday::Weekday;
|
package/src/lib.rs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
mod js;
|
package/tsconfig.eslint.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"emitDecoratorMetadata": true,
|
|
6
|
-
"experimentalDecorators": true,
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"target": "es2017",
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"outDir": "./dist",
|
|
11
|
-
"baseUrl": "./",
|
|
12
|
-
"incremental": true,
|
|
13
|
-
"removeComments": true,
|
|
14
|
-
"allowUnreachableCode": false,
|
|
15
|
-
"allowUnusedLabels": false,
|
|
16
|
-
"noFallthroughCasesInSwitch": true,
|
|
17
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
18
|
-
"noUncheckedIndexedAccess": true,
|
|
19
|
-
"noImplicitOverride": true,
|
|
20
|
-
"noUnusedLocals": true,
|
|
21
|
-
"noUnusedParameters": true,
|
|
22
|
-
"strict": true
|
|
23
|
-
}
|
|
24
|
-
}
|