Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for chrono::DateTime<T> #114

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## [Unreleased]
### Added
- `Ruby::time_nano_new`, `Time::tv_sec`, `Time::tv_usec` and `Time::tv_nsec`.
- The `chrono` feature can be enabled to allow automatic conversions
between `chrono::DateTime<Utc>` and `chrono::DateTime<FixedOffset>` and Ruby `Time` objects.

### Changed
- Conversions between Ruby's `Time` and Rust's `SystemTime` now preserve
Expand Down
234 changes: 234 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ exclude = [
[features]
default = ["old-api"]
bytes = ["dep:bytes"]
chrono = ["dep:chrono"]
embed = ["rb-sys/link-ruby"]
old-api = []
rb-sys = []

[dependencies]
bytes = { version = "1", optional = true }
chrono = { version = "0.4.38", optional = true }
magnus-macros = { version = "0.6.0", path = "magnus-macros" }
rb-sys = { version = "0.9.85", default-features = false, features = [
"bindgen-rbimpls",
Expand All @@ -42,6 +44,7 @@ magnus = { path = ".", default-features = false, features = [
"embed",
"rb-sys",
"bytes",
"chrono",
] }
rb-sys = { version = "0.9", default-features = false, features = [
"stable-api-compiled-fallback",
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ See `magnus::TryConvert` for more details.
| `i8`,`i16`,`i32`,`i64`,`isize`, `magnus::Integer` | `Integer`, `#to_int` |
| `u8`,`u16`,`u32`,`u64`,`usize` | `Integer`, `#to_int` |
| `f32`,`f64`, `magnus::Float` | `Float`, `Numeric` |
| `String`, `PathBuf`, `char`, `magnus::RString`, `bytes::Bytes`\*\*\* | `String`, `#to_str` |
| `String`, `PathBuf`, `char`, `magnus::RString`, `bytes::Bytes` | `String`, `#to_str` |
| `magnus::Symbol` | `Symbol`, `#to_sym` |
| `bool` | any object |
| `magnus::Range` | `Range` |
Expand All @@ -329,17 +329,19 @@ See `magnus::TryConvert` for more details.
| `[T; N]` | `[T]`, `#to_ary` |
| `magnus::RArray` | `Array`, `#to_ary` |
| `magnus::RHash` | `Hash`, `#to_hash` |
| `std::time::SystemTime`, `magnus::Time` | `Time` |
| `std::time::SystemTime`, `magnus::Time`, `chrono::DateTime<T>`§ | `Time` |
| `magnus::Value` | any object |
| `Vec<T>`\* | `[T]`, `#to_ary` |
| `HashMap<K, V>`\* | `{K => V}`, `#to_hash` |
| `&T`, `typed_data::Obj<T>` where `T: TypedData`\*\* | instance of `<T as TypedData>::class()` |
| `&T`, `typed_data::Obj<T>` where `T: TypedData` | instance of `<T as TypedData>::class()` |

\* when converting to `Vec` and `HashMap` the types of `T`/`K`,`V` must be native Rust types.

\*\* see the `wrap` macro.
see the `wrap` macro.

\*\*\* when the `bytes` feature is enabled
‡ when the `bytes` feature is enabled

§ when the `chrono` feature is enabled; `T` can be `Utc` or `FixedOffset`.

### Rust returning / passing values to Ruby

Expand All @@ -360,9 +362,9 @@ and `magnus::ArgList` for some additional details.
| `(T, U)`, `(T, U, V)`, etc, `[T; N]`, `Vec<T>` | `Array` |
| `HashMap<K, V>` | `Hash` |
| `std::time::SystemTime` | `Time` |
| `T`, `typed_data::Obj<T>` where `T: TypedData`\*\* | instance of `<T as TypedData>::class()` |
| `T`, `typed_data::Obj<T>` where `T: TypedData`\* | instance of `<T as TypedData>::class()` |

\*\* see the `wrap` macro.
\* see the `wrap` macro.

### Conversions via Serde

Expand Down
Loading