Skip to content

Commit

Permalink
feat(datetime): add toRFC3339 method (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomquist authored May 5, 2024
1 parent adb6158 commit 980a66b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/js/rrule_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ impl RRuleDateTime {
self.date_time.to_string()
}

#[napi(js_name = "toRFC3339")]
pub fn to_rfc3339(&self) -> String {
self.date_time.to_rfc3339()
}

#[napi(ts_return_type = "Date")]
pub fn to_date(&self, env: Env) -> napi::Result<napi::JsDate> {
env.create_date(self.date_time.timestamp_millis() as f64)
Expand Down
3 changes: 2 additions & 1 deletion tests/datetime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ test.each([new Date(873205200000), 873205200000])(
(input) => {
const rruleDateTime = new RRuleDateTime(input, 'US/Eastern');

expect(rruleDateTime.toString()).toBe('1997-09-02 09:00:00 EDT');
expect(rruleDateTime.toDate()).toEqual(new Date(873205200000));
expect(rruleDateTime.toString()).toBe('1997-09-02 09:00:00 EDT');
expect(rruleDateTime.toRFC3339()).toBe('1997-09-02T09:00:00-04:00');
expect(rruleDateTime.timestamp).toBe(873205200000);
expect(rruleDateTime.timezone.isLocal).toBe(false);
expect(rruleDateTime.timezone.name).toBe('US/Eastern');
Expand Down

0 comments on commit 980a66b

Please sign in to comment.