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 FFI for DateTimeFormat #2164

Merged
merged 2 commits into from
Jul 16, 2022
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 Cargo.lock

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

2 changes: 2 additions & 0 deletions ffi/diplomat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ deserialize_bincode_1 = ["icu_provider/deserialize_bincode_1"]

[dependencies]
fixed_decimal = { version = "0.3", path = "../../utils/fixed_decimal", features = ["ryu"] }
icu_calendar = { version = "0.6", path = "../../components/calendar"}
icu_codepointtrie = { version = "0.4.0", path = "../../utils/codepointtrie"}
icu_datetime = { version = "0.6", path = "../../components/datetime/", features = ["serde"] }
icu_decimal = { version = "0.6", path = "../../components/decimal/", features = ["serde"] }
icu_locale_canonicalizer = { version = "0.6", path = "../../components/locale_canonicalizer", features = ["serde"] }
icu_locid = { version = "0.6", path = "../../components/locid", features = ["serde"] }
Expand Down
25 changes: 25 additions & 0 deletions ffi/diplomat/c/include/ICU4XDateLength.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef ICU4XDateLength_H
#define ICU4XDateLength_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum ICU4XDateLength {
ICU4XDateLength_Full = 0,
ICU4XDateLength_Long = 1,
ICU4XDateLength_Medium = 2,
ICU4XDateLength_Short = 3,
} ICU4XDateLength;

void ICU4XDateLength_destroy(ICU4XDateLength* self);

#ifdef __cplusplus
}
#endif
#endif
16 changes: 16 additions & 0 deletions ffi/diplomat/c/include/ICU4XError.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ typedef enum ICU4XError {
ICU4XError_DecimalLimitError = 1280,
ICU4XError_DecimalSyntaxError = 1281,
ICU4XError_PluralParserError = 1536,
ICU4XError_DateTimeParseError = 1792,
ICU4XError_DateTimeOverflowError = 1793,
ICU4XError_DateTimeUnderflowError = 1794,
ICU4XError_DateTimeInvalidTimeZoneOffsetError = 1795,
ICU4XError_DateTimeOutOfRangeError = 1796,
ICU4XError_DateTimeMissingInputError = 1797,
ICU4XError_DateTimeFormatPatternError = 2048,
ICU4XError_DateTimeFormatMissingInputFieldError = 2049,
ICU4XError_DateTimeFormatSkeletonError = 2050,
ICU4XError_DateTimeFormatUnsupportedFieldError = 2051,
ICU4XError_DateTimeFormatUnsupportedOptionsError = 2052,
ICU4XError_DateTimeFormatMissingWeekdaySymbolError = 2053,
ICU4XError_DateTimeFormatMissingMonthSymbolError = 2054,
ICU4XError_DateTimeFormatMissingEraSymbolError = 2055,
ICU4XError_DateTimeFormatFixedDecimalError = 2056,
ICU4XError_DateTimeFormatMismatchedAnyCalendarError = 2057,
} ICU4XError;

void ICU4XError_destroy(ICU4XError* self);
Expand Down
29 changes: 29 additions & 0 deletions ffi/diplomat/c/include/ICU4XGregorianDateFormat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef ICU4XGregorianDateFormat_H
#define ICU4XGregorianDateFormat_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ICU4XGregorianDateFormat ICU4XGregorianDateFormat;
#include "ICU4XLocale.h"
#include "ICU4XDataProvider.h"
#include "ICU4XDateLength.h"
#include "diplomat_result_box_ICU4XGregorianDateFormat_ICU4XError.h"
#include "ICU4XGregorianDateTime.h"
#include "diplomat_result_void_ICU4XError.h"

diplomat_result_box_ICU4XGregorianDateFormat_ICU4XError ICU4XGregorianDateFormat_try_new(const ICU4XLocale* locale, const ICU4XDataProvider* provider, ICU4XDateLength length);

diplomat_result_void_ICU4XError ICU4XGregorianDateFormat_format_datetime(const ICU4XGregorianDateFormat* self, const ICU4XGregorianDateTime* value, DiplomatWriteable* write);
void ICU4XGregorianDateFormat_destroy(ICU4XGregorianDateFormat* self);

#ifdef __cplusplus
}
#endif
#endif
22 changes: 22 additions & 0 deletions ffi/diplomat/c/include/ICU4XGregorianDateTime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef ICU4XGregorianDateTime_H
#define ICU4XGregorianDateTime_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ICU4XGregorianDateTime ICU4XGregorianDateTime;
#include "diplomat_result_box_ICU4XGregorianDateTime_ICU4XError.h"

diplomat_result_box_ICU4XGregorianDateTime_ICU4XError ICU4XGregorianDateTime_try_new(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
void ICU4XGregorianDateTime_destroy(ICU4XGregorianDateTime* self);

#ifdef __cplusplus
}
#endif
#endif
31 changes: 31 additions & 0 deletions ffi/diplomat/c/include/ICU4XGregorianDateTimeFormat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef ICU4XGregorianDateTimeFormat_H
#define ICU4XGregorianDateTimeFormat_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ICU4XGregorianDateTimeFormat ICU4XGregorianDateTimeFormat;
#include "ICU4XLocale.h"
#include "ICU4XDataProvider.h"
#include "ICU4XDateLength.h"
#include "ICU4XTimeLength.h"
#include "ICU4XHourCyclePreference.h"
#include "diplomat_result_box_ICU4XGregorianDateTimeFormat_ICU4XError.h"
#include "ICU4XGregorianDateTime.h"
#include "diplomat_result_void_ICU4XError.h"

diplomat_result_box_ICU4XGregorianDateTimeFormat_ICU4XError ICU4XGregorianDateTimeFormat_try_new(const ICU4XLocale* locale, const ICU4XDataProvider* provider, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XHourCyclePreference time_preferences);

diplomat_result_void_ICU4XError ICU4XGregorianDateTimeFormat_format_datetime(const ICU4XGregorianDateTimeFormat* self, const ICU4XGregorianDateTime* value, DiplomatWriteable* write);
void ICU4XGregorianDateTimeFormat_destroy(ICU4XGregorianDateTimeFormat* self);

#ifdef __cplusplus
}
#endif
#endif
30 changes: 30 additions & 0 deletions ffi/diplomat/c/include/ICU4XGregorianTimeFormat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef ICU4XGregorianTimeFormat_H
#define ICU4XGregorianTimeFormat_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ICU4XGregorianTimeFormat ICU4XGregorianTimeFormat;
#include "ICU4XLocale.h"
#include "ICU4XDataProvider.h"
#include "ICU4XTimeLength.h"
#include "ICU4XHourCyclePreference.h"
#include "diplomat_result_box_ICU4XGregorianTimeFormat_ICU4XError.h"
#include "ICU4XGregorianDateTime.h"
#include "diplomat_result_void_ICU4XError.h"

diplomat_result_box_ICU4XGregorianTimeFormat_ICU4XError ICU4XGregorianTimeFormat_try_new(const ICU4XLocale* locale, const ICU4XDataProvider* provider, ICU4XTimeLength length, ICU4XHourCyclePreference preferences);

diplomat_result_void_ICU4XError ICU4XGregorianTimeFormat_format_datetime(const ICU4XGregorianTimeFormat* self, const ICU4XGregorianDateTime* value, DiplomatWriteable* write);
void ICU4XGregorianTimeFormat_destroy(ICU4XGregorianTimeFormat* self);

#ifdef __cplusplus
}
#endif
#endif
26 changes: 26 additions & 0 deletions ffi/diplomat/c/include/ICU4XHourCyclePreference.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef ICU4XHourCyclePreference_H
#define ICU4XHourCyclePreference_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum ICU4XHourCyclePreference {
ICU4XHourCyclePreference_H24 = 0,
ICU4XHourCyclePreference_H23 = 1,
ICU4XHourCyclePreference_H12 = 2,
ICU4XHourCyclePreference_H11 = 3,
ICU4XHourCyclePreference_None = 4,
} ICU4XHourCyclePreference;

void ICU4XHourCyclePreference_destroy(ICU4XHourCyclePreference* self);

#ifdef __cplusplus
}
#endif
#endif
25 changes: 25 additions & 0 deletions ffi/diplomat/c/include/ICU4XTimeLength.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef ICU4XTimeLength_H
#define ICU4XTimeLength_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum ICU4XTimeLength {
ICU4XTimeLength_Full = 0,
ICU4XTimeLength_Long = 1,
ICU4XTimeLength_Medium = 2,
ICU4XTimeLength_Short = 3,
} ICU4XTimeLength;

void ICU4XTimeLength_destroy(ICU4XTimeLength* self);

#ifdef __cplusplus
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef diplomat_result_box_ICU4XGregorianDateFormat_ICU4XError_H
#define diplomat_result_box_ICU4XGregorianDateFormat_ICU4XError_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif
typedef struct ICU4XGregorianDateFormat ICU4XGregorianDateFormat;
#include "ICU4XError.h"
typedef struct diplomat_result_box_ICU4XGregorianDateFormat_ICU4XError {
union {
ICU4XGregorianDateFormat* ok;
ICU4XError err;
};
bool is_ok;
} diplomat_result_box_ICU4XGregorianDateFormat_ICU4XError;
#ifdef __cplusplus
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef diplomat_result_box_ICU4XGregorianDateTimeFormat_ICU4XError_H
#define diplomat_result_box_ICU4XGregorianDateTimeFormat_ICU4XError_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif
typedef struct ICU4XGregorianDateTimeFormat ICU4XGregorianDateTimeFormat;
#include "ICU4XError.h"
typedef struct diplomat_result_box_ICU4XGregorianDateTimeFormat_ICU4XError {
union {
ICU4XGregorianDateTimeFormat* ok;
ICU4XError err;
};
bool is_ok;
} diplomat_result_box_ICU4XGregorianDateTimeFormat_ICU4XError;
#ifdef __cplusplus
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef diplomat_result_box_ICU4XGregorianDateTime_ICU4XError_H
#define diplomat_result_box_ICU4XGregorianDateTime_ICU4XError_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif
typedef struct ICU4XGregorianDateTime ICU4XGregorianDateTime;
#include "ICU4XError.h"
typedef struct diplomat_result_box_ICU4XGregorianDateTime_ICU4XError {
union {
ICU4XGregorianDateTime* ok;
ICU4XError err;
};
bool is_ok;
} diplomat_result_box_ICU4XGregorianDateTime_ICU4XError;
#ifdef __cplusplus
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef diplomat_result_box_ICU4XGregorianTimeFormat_ICU4XError_H
#define diplomat_result_box_ICU4XGregorianTimeFormat_ICU4XError_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif
typedef struct ICU4XGregorianTimeFormat ICU4XGregorianTimeFormat;
#include "ICU4XError.h"
typedef struct diplomat_result_box_ICU4XGregorianTimeFormat_ICU4XError {
union {
ICU4XGregorianTimeFormat* ok;
ICU4XError err;
};
bool is_ok;
} diplomat_result_box_ICU4XGregorianTimeFormat_ICU4XError;
#ifdef __cplusplus
}
#endif
#endif
12 changes: 12 additions & 0 deletions ffi/diplomat/cpp/docs/source/calendar_ffi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
``calendar::ffi``
=================

.. cpp:class:: ICU4XGregorianDateTime

An ICU4X DateTime object capable of containing a Gregorian date and time.
See the `Rust documentation <https://unicode-org.github.io/icu4x-docs/doc/icu/calendar/struct.DateTime.html>`__ for more information.

.. cpp:function:: static diplomat::result<ICU4XGregorianDateTime, ICU4XError> try_new(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)

Creates a new :cpp:class:`ICU4XGregorianDateTime` from the specified date and time.
See the `Rust documentation <https://unicode-org.github.io/icu4x-docs/doc/icu/calendar/struct.DateTime.html#method.new_gregorian_datetime>`__ for more information.
Loading