Skip to content

Commit cfb438b

Browse files
Add underlying support for NaiveDate to LocalDate
1 parent 6973e77 commit cfb438b

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

crates/bitwarden-core/src/uniffi_support.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ uniffi::custom_type!(Uuid, String, {
2121
lower: |obj| obj.to_string(),
2222
});
2323

24+
type NaiveDate = chrono::NaiveDate;
25+
uniffi::custom_type!(NaiveDate, String, {
26+
remote,
27+
try_lift: |val| convert_result(NaiveDate::from_str(&val)),
28+
lower: |obj| obj.to_string(),
29+
});
30+
2431
// Uniffi doesn't emit unused types, this is a dummy record to ensure that the custom type
2532
// converters are emitted
2633
#[allow(dead_code)]
2734
#[derive(uniffi::Record)]
2835
struct UniffiConverterDummyRecord {
2936
uuid: Uuid,
3037
date: DateTime,
38+
naive_date: NaiveDate,
3139
}
3240

3341
uniffi::custom_type!(SignedSecurityState, String, {

crates/bitwarden-core/uniffi.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ android = true
55
# Temporary workaround for https://github.com/mozilla/uniffi-rs/issues/2740
66
omit_checksums = true
77

8+
[bindings.kotlin.custom_types.NaiveDate]
9+
type_name = "LocalDate"
10+
imports = ["java.time.LocalDate"]
11+
into_custom = "LocalDate.parse({})"
12+
from_custom = "{}.toString()"
13+
814
[bindings.swift]
915
ffi_module_name = "BitwardenCoreFFI"
1016
module_name = "BitwardenCore"

crates/bitwarden-uniffi/src/uniffi_support.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use uuid::Uuid;
55
type DateTime = chrono::DateTime<chrono::Utc>;
66
uniffi::use_remote_type!(bitwarden_core::DateTime);
77

8+
type NaiveDate = chrono::NaiveDate;
9+
uniffi::use_remote_type!(bitwarden_core::NaiveDate);
10+
811
uniffi::use_remote_type!(bitwarden_core::Uuid);
912

1013
uniffi::use_remote_type!(bitwarden_crypto::safe::PasswordProtectedKeyEnvelope);

crates/bitwarden-vault/src/uniffi_support.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ use uuid::Uuid;
22

33
type DateTime = chrono::DateTime<chrono::Utc>;
44
uniffi::use_remote_type!(bitwarden_core::DateTime);
5+
type NaiveDate = chrono::NaiveDate;
6+
uniffi::use_remote_type!(bitwarden_core::NaiveDate);
57
uniffi::use_remote_type!(bitwarden_core::Uuid);

0 commit comments

Comments
 (0)