rrule-rust 1.2.0-next.1 → 1.2.0-next.2

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.
Files changed (3) hide show
  1. package/index.d.ts +3 -0
  2. package/package.json +15 -15
  3. package/src/lib.rs +28 -0
package/index.d.ts CHANGED
@@ -38,6 +38,7 @@ export const enum Month {
38
38
  export type JsRRule = RRule
39
39
  export class RRule {
40
40
  constructor(frequency: Frequency)
41
+ static parse(str: string): RRule
41
42
  get frequency(): Frequency
42
43
  get interval(): number
43
44
  get count(): number | null
@@ -75,11 +76,13 @@ export class RRuleSet {
75
76
  addRrule(jsRrule: RRule): this
76
77
  addExrule(jsRrule: RRule): this
77
78
  addExdate(timestamp: number): this
79
+ addRdate(timestamp: number): this
78
80
  get dtstart(): number
79
81
  get tzid(): string
80
82
  getRrules(): Array<RRule>
81
83
  getExrules(): Array<RRule>
82
84
  getExdates(): Array<number>
85
+ getRdates(): Array<number>
83
86
  all(limit?: number | undefined | null): number[]
84
87
  between(after: number, before: number, inclusive?: boolean | undefined | null): number[]
85
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-rust",
3
- "version": "1.2.0-next.1",
3
+ "version": "1.2.0-next.2",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "keywords": [
@@ -88,19 +88,19 @@
88
88
  "conventional-changelog-conventionalcommits": "^7.0.2"
89
89
  },
90
90
  "optionalDependencies": {
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"
91
+ "@rrule-rust/lib-win32-x64-msvc": "1.2.0-next.2",
92
+ "@rrule-rust/lib-darwin-x64": "1.2.0-next.2",
93
+ "@rrule-rust/lib-linux-x64-gnu": "1.2.0-next.2",
94
+ "@rrule-rust/lib-darwin-arm64": "1.2.0-next.2",
95
+ "@rrule-rust/lib-android-arm64": "1.2.0-next.2",
96
+ "@rrule-rust/lib-linux-arm64-gnu": "1.2.0-next.2",
97
+ "@rrule-rust/lib-linux-arm64-musl": "1.2.0-next.2",
98
+ "@rrule-rust/lib-win32-arm64-msvc": "1.2.0-next.2",
99
+ "@rrule-rust/lib-linux-arm-gnueabihf": "1.2.0-next.2",
100
+ "@rrule-rust/lib-linux-x64-musl": "1.2.0-next.2",
101
+ "@rrule-rust/lib-freebsd-x64": "1.2.0-next.2",
102
+ "@rrule-rust/lib-win32-ia32-msvc": "1.2.0-next.2",
103
+ "@rrule-rust/lib-android-arm-eabi": "1.2.0-next.2",
104
+ "@rrule-rust/lib-darwin-universal": "1.2.0-next.2"
105
105
  }
106
106
  }
package/src/lib.rs CHANGED
@@ -90,6 +90,15 @@ impl JsRRule {
90
90
  JsRRule { rrule }
91
91
  }
92
92
 
93
+ #[napi(factory, ts_return_type = "RRule")]
94
+ pub fn parse(str: String) -> napi::Result<Self> {
95
+ let rrule: RRule<Unvalidated> = str
96
+ .parse()
97
+ .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
98
+
99
+ Ok(JsRRule { rrule })
100
+ }
101
+
93
102
  #[napi(getter)]
94
103
  pub fn frequency(&self) -> napi::Result<JsFrequency> {
95
104
  Ok(map_rust_frequency(self.rrule.get_freq()))
@@ -398,6 +407,15 @@ impl JsRRuleSet {
398
407
  Ok(self)
399
408
  }
400
409
 
410
+ #[napi]
411
+ pub fn add_rdate(&mut self, timestamp: i64) -> napi::Result<&Self> {
412
+ replace_with_or_abort(&mut self.rrule_set, |self_| {
413
+ self_.rdate(timestamp_to_date_with_tz(timestamp, &self.tz))
414
+ });
415
+
416
+ Ok(self)
417
+ }
418
+
401
419
  #[napi(getter)]
402
420
  pub fn dtstart(&self) -> napi::Result<i64> {
403
421
  Ok(self.rrule_set.get_dt_start().timestamp_millis())
@@ -442,6 +460,16 @@ impl JsRRuleSet {
442
460
  .collect();
443
461
  }
444
462
 
463
+ #[napi]
464
+ pub fn get_rdates(&self) -> Vec<i64> {
465
+ return self
466
+ .rrule_set
467
+ .get_rdate()
468
+ .iter()
469
+ .map(|date| date.timestamp_millis())
470
+ .collect();
471
+ }
472
+
445
473
  fn is_after(&self, timestamp: i64, after_timestamp: i64, inclusive: Option<bool>) -> bool {
446
474
  let inclusive = inclusive.unwrap_or(false);
447
475