| 1 |
#ifndef ICU4XGregorianZonedDateTimeFormatter_HPP |
| 2 |
#define ICU4XGregorianZonedDateTimeFormatter_HPP |
| 3 |
#include <stdint.h> |
| 4 |
#include <stddef.h> |
| 5 |
#include <stdbool.h> |
| 6 |
#include <algorithm> |
| 7 |
#include <memory> |
| 8 |
#include <variant> |
| 9 |
#include <optional> |
| 10 |
#include "diplomat_runtime.hpp" |
| 11 |
|
| 12 |
#include "ICU4XGregorianZonedDateTimeFormatter.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XLocale; |
| 16 |
#include "ICU4XDateLength.hpp" |
| 17 |
#include "ICU4XTimeLength.hpp" |
| 18 |
class ICU4XGregorianZonedDateTimeFormatter; |
| 19 |
#include "ICU4XError.hpp" |
| 20 |
struct ICU4XIsoTimeZoneOptions; |
| 21 |
class ICU4XIsoDateTime; |
| 22 |
class ICU4XCustomTimeZone; |
| 23 |
|
| 24 |
/** |
| 25 |
* A destruction policy for using ICU4XGregorianZonedDateTimeFormatter with std::unique_ptr. |
| 26 |
*/ |
| 27 |
struct ICU4XGregorianZonedDateTimeFormatterDeleter { |
| 28 |
void operator()(capi::ICU4XGregorianZonedDateTimeFormatter* l) const noexcept { |
| 29 |
capi::ICU4XGregorianZonedDateTimeFormatter_destroy(l); |
| 30 |
} |
| 31 |
}; |
| 32 |
|
| 33 |
/** |
| 34 |
* An object capable of formatting a date time with time zone to a string. |
| 35 |
* |
| 36 |
* See the [Rust documentation for `TypedZonedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html) for more information. |
| 37 |
*/ |
| 38 |
class ICU4XGregorianZonedDateTimeFormatter { |
| 39 |
public: |
| 40 |
|
| 41 |
/** |
| 42 |
* Creates a new [`ICU4XGregorianZonedDateTimeFormatter`] from locale data. |
| 43 |
* |
| 44 |
* This function has `date_length` and `time_length` arguments and uses default options |
| 45 |
* for the time zone. |
| 46 |
* |
| 47 |
* See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.try_new) for more information. |
| 48 |
*/ |
| 49 |
static diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); |
| 50 |
|
| 51 |
/** |
| 52 |
* Creates a new [`ICU4XGregorianZonedDateTimeFormatter`] from locale data. |
| 53 |
* |
| 54 |
* This function has `date_length` and `time_length` arguments and uses an ISO-8601 style |
| 55 |
* fallback for the time zone with the given configurations. |
| 56 |
* |
| 57 |
* See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.try_new) for more information. |
| 58 |
*/ |
| 59 |
static diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> create_with_lengths_and_iso_8601_time_zone_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XIsoTimeZoneOptions zone_options); |
| 60 |
|
| 61 |
/** |
| 62 |
* Formats a [`ICU4XIsoDateTime`] and [`ICU4XCustomTimeZone`] to a string. |
| 63 |
* |
| 64 |
* See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.format) for more information. |
| 65 |
*/ |
| 66 |
template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_datetime_with_custom_time_zone_to_writeable(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone, W& write) const; |
| 67 |
|
| 68 |
/** |
| 69 |
* Formats a [`ICU4XIsoDateTime`] and [`ICU4XCustomTimeZone`] to a string. |
| 70 |
* |
| 71 |
* See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.format) for more information. |
| 72 |
*/ |
| 73 |
diplomat::result<std::string, ICU4XError> format_iso_datetime_with_custom_time_zone(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone) const; |
| 74 |
inline const capi::ICU4XGregorianZonedDateTimeFormatter* AsFFI() const { return this->inner.get(); } |
| 75 |
inline capi::ICU4XGregorianZonedDateTimeFormatter* AsFFIMut() { return this->inner.get(); } |
| 76 |
inline explicit ICU4XGregorianZonedDateTimeFormatter(capi::ICU4XGregorianZonedDateTimeFormatter* i) : inner(i) {} |
| 77 |
ICU4XGregorianZonedDateTimeFormatter() = default; |
| 78 |
ICU4XGregorianZonedDateTimeFormatter(ICU4XGregorianZonedDateTimeFormatter&&) noexcept = default; |
| 79 |
ICU4XGregorianZonedDateTimeFormatter& operator=(ICU4XGregorianZonedDateTimeFormatter&& other) noexcept = default; |
| 80 |
private: |
| 81 |
std::unique_ptr<capi::ICU4XGregorianZonedDateTimeFormatter, ICU4XGregorianZonedDateTimeFormatterDeleter> inner; |
| 82 |
}; |
| 83 |
|
| 84 |
#include "ICU4XDataProvider.hpp" |
| 85 |
#include "ICU4XLocale.hpp" |
| 86 |
#include "ICU4XIsoTimeZoneOptions.hpp" |
| 87 |
#include "ICU4XIsoDateTime.hpp" |
| 88 |
#include "ICU4XCustomTimeZone.hpp" |
| 89 |
|
| 90 |
inline diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> ICU4XGregorianZonedDateTimeFormatter::create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length) { |
| 91 |
auto diplomat_result_raw_out_value = capi::ICU4XGregorianZonedDateTimeFormatter_create_with_lengths(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length), static_cast<capi::ICU4XTimeLength>(time_length)); |
| 92 |
diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> diplomat_result_out_value; |
| 93 |
if (diplomat_result_raw_out_value.is_ok) { |
| 94 |
diplomat_result_out_value = diplomat::Ok<ICU4XGregorianZonedDateTimeFormatter>(ICU4XGregorianZonedDateTimeFormatter(diplomat_result_raw_out_value.ok)); |
| 95 |
} else { |
| 96 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 97 |
} |
| 98 |
return diplomat_result_out_value; |
| 99 |
} |
| 100 |
inline diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> ICU4XGregorianZonedDateTimeFormatter::create_with_lengths_and_iso_8601_time_zone_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XIsoTimeZoneOptions zone_options) { |
| 101 |
ICU4XIsoTimeZoneOptions diplomat_wrapped_struct_zone_options = zone_options; |
| 102 |
auto diplomat_result_raw_out_value = capi::ICU4XGregorianZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length), static_cast<capi::ICU4XTimeLength>(time_length), capi::ICU4XIsoTimeZoneOptions{ .format = static_cast<capi::ICU4XIsoTimeZoneFormat>(diplomat_wrapped_struct_zone_options.format), .minutes = static_cast<capi::ICU4XIsoTimeZoneMinuteDisplay>(diplomat_wrapped_struct_zone_options.minutes), .seconds = static_cast<capi::ICU4XIsoTimeZoneSecondDisplay>(diplomat_wrapped_struct_zone_options.seconds) }); |
| 103 |
diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> diplomat_result_out_value; |
| 104 |
if (diplomat_result_raw_out_value.is_ok) { |
| 105 |
diplomat_result_out_value = diplomat::Ok<ICU4XGregorianZonedDateTimeFormatter>(ICU4XGregorianZonedDateTimeFormatter(diplomat_result_raw_out_value.ok)); |
| 106 |
} else { |
| 107 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 108 |
} |
| 109 |
return diplomat_result_out_value; |
| 110 |
} |
| 111 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XGregorianZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone_to_writeable(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone, W& write) const { |
| 112 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 113 |
auto diplomat_result_raw_out_value = capi::ICU4XGregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(this->inner.get(), datetime.AsFFI(), time_zone.AsFFI(), &write_writer); |
| 114 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 115 |
if (diplomat_result_raw_out_value.is_ok) { |
| 116 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 117 |
} else { |
| 118 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 119 |
} |
| 120 |
return diplomat_result_out_value; |
| 121 |
} |
| 122 |
inline diplomat::result<std::string, ICU4XError> ICU4XGregorianZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone) const { |
| 123 |
std::string diplomat_writeable_string; |
| 124 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 125 |
auto diplomat_result_raw_out_value = capi::ICU4XGregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(this->inner.get(), datetime.AsFFI(), time_zone.AsFFI(), &diplomat_writeable_out); |
| 126 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 127 |
if (diplomat_result_raw_out_value.is_ok) { |
| 128 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 129 |
} else { |
| 130 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 131 |
} |
| 132 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 133 |
} |
| 134 |
#endif |