rrule-rust 1.1.5 → 1.2.0-next.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/.releaserc ADDED
@@ -0,0 +1,47 @@
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/github",
43
+ "@semantic-release/npm",
44
+ "@semantic-release/git"
45
+ ],
46
+ "branches": ["+([0-9])?(.{+([0-9]),x}).x", "master", {"name": "next", "prerelease": true}]
47
+ }
package/index.d.ts CHANGED
@@ -77,6 +77,9 @@ export class RRuleSet {
77
77
  addExdate(timestamp: number): this
78
78
  get dtstart(): number
79
79
  get tzid(): string
80
+ getRrules(): Array<RRule>
81
+ getExrules(): Array<RRule>
82
+ getExdates(): Array<number>
80
83
  all(limit?: number | undefined | null): number[]
81
84
  between(after: number, before: number, inclusive?: boolean | undefined | null): number[]
82
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-rust",
3
- "version": "1.1.5",
3
+ "version": "1.2.0-next.1",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "keywords": [
@@ -40,6 +40,7 @@
40
40
  "license": "MIT",
41
41
  "devDependencies": {
42
42
  "@napi-rs/cli": "^2.15.1",
43
+ "@semantic-release/git": "^10.0.1",
43
44
  "@types/jest": "^29.5.0",
44
45
  "@types/node": "^18.15.5",
45
46
  "@typescript-eslint/eslint-plugin": "^5.50.0",
@@ -55,16 +56,17 @@
55
56
  "pre-commit": "^1.2.2",
56
57
  "prettier": "^2.8.3",
57
58
  "rrule": "^2.7.2",
59
+ "semantic-release": "^22.0.12",
58
60
  "ts-jest": "^29.0.5",
59
61
  "ts-node": "^10.9.1",
60
62
  "typescript": "^4.9.4"
61
63
  },
62
64
  "pre-commit": [
63
- "lint:fix-staged",
64
- "test"
65
+ "lint:fix-staged"
65
66
  ],
66
67
  "lint-staged": {
67
- "**/*.{js,ts,json}": "eslint --fix --max-warnings=0"
68
+ "**/*.{js,ts,json}": "eslint --fix --max-warnings=0",
69
+ "**/*.rs": "rustfmt"
68
70
  },
69
71
  "engines": {
70
72
  "node": ">= 10"
@@ -78,24 +80,27 @@
78
80
  "universal": "napi universal",
79
81
  "version": "napi version",
80
82
  "benchmark": "ts-node ./benchmark/index.ts",
81
- "lint": "eslint \"**/*.{js,ts,json}\" --max-warnings=0",
82
- "lint:fix": "yarn lint --fix",
83
+ "lint": "cargo fmt --all -- --check && eslint \"**/*.{js,ts,json}\" --max-warnings=0",
84
+ "lint:fix": "cargo fmt --all && yarn lint --fix",
83
85
  "lint:fix-staged": "lint-staged"
84
86
  },
87
+ "dependencies": {
88
+ "conventional-changelog-conventionalcommits": "^7.0.2"
89
+ },
85
90
  "optionalDependencies": {
86
- "@rrule-rust/lib-win32-x64-msvc": "1.1.5",
87
- "@rrule-rust/lib-darwin-x64": "1.1.5",
88
- "@rrule-rust/lib-linux-x64-gnu": "1.1.5",
89
- "@rrule-rust/lib-darwin-arm64": "1.1.5",
90
- "@rrule-rust/lib-android-arm64": "1.1.5",
91
- "@rrule-rust/lib-linux-arm64-gnu": "1.1.5",
92
- "@rrule-rust/lib-linux-arm64-musl": "1.1.5",
93
- "@rrule-rust/lib-win32-arm64-msvc": "1.1.5",
94
- "@rrule-rust/lib-linux-arm-gnueabihf": "1.1.5",
95
- "@rrule-rust/lib-linux-x64-musl": "1.1.5",
96
- "@rrule-rust/lib-freebsd-x64": "1.1.5",
97
- "@rrule-rust/lib-win32-ia32-msvc": "1.1.5",
98
- "@rrule-rust/lib-android-arm-eabi": "1.1.5",
99
- "@rrule-rust/lib-darwin-universal": "1.1.5"
91
+ "@rrule-rust/lib-win32-x64-msvc": "1.2.0-next.1",
92
+ "@rrule-rust/lib-darwin-x64": "1.2.0-next.1",
93
+ "@rrule-rust/lib-linux-x64-gnu": "1.2.0-next.1",
94
+ "@rrule-rust/lib-darwin-arm64": "1.2.0-next.1",
95
+ "@rrule-rust/lib-android-arm64": "1.2.0-next.1",
96
+ "@rrule-rust/lib-linux-arm64-gnu": "1.2.0-next.1",
97
+ "@rrule-rust/lib-linux-arm64-musl": "1.2.0-next.1",
98
+ "@rrule-rust/lib-win32-arm64-msvc": "1.2.0-next.1",
99
+ "@rrule-rust/lib-linux-arm-gnueabihf": "1.2.0-next.1",
100
+ "@rrule-rust/lib-linux-x64-musl": "1.2.0-next.1",
101
+ "@rrule-rust/lib-freebsd-x64": "1.2.0-next.1",
102
+ "@rrule-rust/lib-win32-ia32-msvc": "1.2.0-next.1",
103
+ "@rrule-rust/lib-android-arm-eabi": "1.2.0-next.1",
104
+ "@rrule-rust/lib-darwin-universal": "1.2.0-next.1"
100
105
  }
101
106
  }
package/src/lib.rs CHANGED
@@ -46,6 +46,36 @@ pub enum JsMonth {
46
46
  December,
47
47
  }
48
48
 
49
+ fn to_unvalidated(rrule: &RRule) -> RRule<Unvalidated> {
50
+ let by_month = rrule
51
+ .get_by_month()
52
+ .iter()
53
+ .map(|m| Month::try_from(*m).unwrap())
54
+ .collect::<Vec<_>>();
55
+ let mut unvalidated = RRule::new(rrule.get_freq())
56
+ .interval(rrule.get_interval())
57
+ .week_start(rrule.get_week_start())
58
+ .by_set_pos(rrule.get_by_set_pos().to_vec())
59
+ .by_month(&by_month)
60
+ .by_month_day(rrule.get_by_month_day().to_vec())
61
+ .by_year_day(rrule.get_by_year_day().to_vec())
62
+ .by_week_no(rrule.get_by_week_no().to_vec())
63
+ .by_weekday(rrule.get_by_weekday().to_vec())
64
+ .by_hour(rrule.get_by_hour().to_vec())
65
+ .by_minute(rrule.get_by_minute().to_vec())
66
+ .by_second(rrule.get_by_second().to_vec());
67
+
68
+ if let Some(count) = rrule.get_count() {
69
+ unvalidated = unvalidated.count(count);
70
+ }
71
+
72
+ if let Some(until) = rrule.get_until() {
73
+ unvalidated = unvalidated.until(*until);
74
+ }
75
+
76
+ unvalidated
77
+ }
78
+
49
79
  #[napi(js_name = "RRule")]
50
80
  pub struct JsRRule {
51
81
  rrule: RRule<Unvalidated>,
@@ -297,7 +327,13 @@ impl JsRRule {
297
327
  }
298
328
 
299
329
  pub fn validate(&self, dt_start: DateTime<Tz>) -> napi::Result<RRule> {
300
- return Ok(self.rrule.clone().validate(dt_start).map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?);
330
+ return Ok(
331
+ self
332
+ .rrule
333
+ .clone()
334
+ .validate(dt_start)
335
+ .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?,
336
+ );
301
337
  }
302
338
  }
303
339
 
@@ -320,7 +356,9 @@ impl JsRRuleSet {
320
356
 
321
357
  #[napi(factory, ts_return_type = "RRuleSet")]
322
358
  pub fn parse(str: String) -> napi::Result<Self> {
323
- let rrule_set: RRuleSet = str.parse().map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
359
+ let rrule_set: RRuleSet = str
360
+ .parse()
361
+ .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
324
362
  let dtstart = rrule_set.get_dt_start();
325
363
  let tz = dtstart.timezone();
326
364
 
@@ -370,19 +408,39 @@ impl JsRRuleSet {
370
408
  Ok(String::from(self.tz.name()))
371
409
  }
372
410
 
373
- /*#[napi(ts_return_type="RRule[]")]
374
- pub fn get_rrules(&self, env: Env) -> napi::Result<Array> {
375
- let mut arr = env.create_array(0).unwrap();
376
- let rrules = self.rrule_set.get_rrule();
411
+ #[napi]
412
+ pub fn get_rrules(&self) -> Vec<JsRRule> {
413
+ return self
414
+ .rrule_set
415
+ .get_rrule()
416
+ .iter()
417
+ .map(|rrule| JsRRule {
418
+ rrule: to_unvalidated(rrule),
419
+ })
420
+ .collect();
421
+ }
377
422
 
378
- for rrule in rrules.iter() {
379
- arr.insert(JsRRule {
380
- freq: map_rust_frequency(rrule.get_freq())
381
- }).unwrap();
382
- }
423
+ #[napi]
424
+ pub fn get_exrules(&self) -> Vec<JsRRule> {
425
+ return self
426
+ .rrule_set
427
+ .get_exrule()
428
+ .iter()
429
+ .map(|rrule| JsRRule {
430
+ rrule: to_unvalidated(rrule),
431
+ })
432
+ .collect();
433
+ }
383
434
 
384
- Ok(arr)
385
- }*/
435
+ #[napi]
436
+ pub fn get_exdates(&self) -> Vec<i64> {
437
+ return self
438
+ .rrule_set
439
+ .get_exdate()
440
+ .iter()
441
+ .map(|date| date.timestamp_millis())
442
+ .collect();
443
+ }
386
444
 
387
445
  fn is_after(&self, timestamp: i64, after_timestamp: i64, inclusive: Option<bool>) -> bool {
388
446
  let inclusive = inclusive.unwrap_or(false);
@@ -480,15 +538,6 @@ fn map_js_frequency(freq: JsFrequency) -> Frequency {
480
538
  }
481
539
  }
482
540
 
483
- /*fn map_rust_rrule (rrule: RRule) -> JsRRule {
484
- JsRRule {
485
- freq: map_rust_frequency(rrule.get_freq()),
486
- interval: Some(rrule.get_interval()),
487
- count: rrule.get_count(),
488
- by_weekday:
489
- }
490
- }*/
491
-
492
541
  fn map_js_weekday(weekday: JsWeekday) -> Weekday {
493
542
  match weekday {
494
543
  JsWeekday::Monday => Weekday::Mon,
@@ -549,7 +598,9 @@ fn map_rust_month(month: &u8) -> JsMonth {
549
598
  }
550
599
 
551
600
  fn map_js_tz(tz: &str) -> napi::Result<Tz> {
552
- let chrono_tz = tz.parse().map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
601
+ let chrono_tz = tz
602
+ .parse()
603
+ .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
553
604
  Ok(Tz::Tz(chrono_tz))
554
605
  }
555
606