Skip to content

Commit

Permalink
Support iOS, don't compile error if unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Jul 22, 2022
1 parent 7b3b806 commit 03d1b3b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ categories = ["date-and-time", "internationalization", "os"]
readme = "README.md"
edition = "2018"

[target.'cfg(target_os = "macos")'.dependencies]
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation = "0.9"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
21 changes: 12 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#[cfg_attr(target_os = "linux", path = "tz_linux.rs")]
#[cfg_attr(target_os = "windows", path = "tz_windows.rs")]
#[cfg_attr(target_os = "macos", path = "tz_macos.rs")]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), path = "tz_macos.rs")]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
path = "tz_wasm32.rs"
Expand All @@ -44,20 +44,22 @@ pub enum GetTimezoneError {
IoError(std::io::Error),
/// Platform-specific error from the operating system
OsError,
/// Unsupported target OS
Unsupported,
}

impl std::error::Error for GetTimezoneError {}

impl std::fmt::Display for GetTimezoneError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
use GetTimezoneError::*;
let descr = match self {
FailedParsingString => "GetTimezoneError::FailedParsingString",
IoError(_) => "GetTimezoneError::IoError(_)",
OsError => "OsError",
};

write!(f, "{}", descr)
f.write_str(match self {
Self::FailedParsingString => "GetTimezoneError::FailedParsingString",
Self::IoError(err) => return err.fmt(f),
Self::OsError => "OsError",
Self::Unsupported => {
"Unsupported operating system, please file a bug report to iana-time-zone"
}
})
}
}

Expand All @@ -71,6 +73,7 @@ impl std::convert::From<std::io::Error> for GetTimezoneError {
///
/// See the module-level documentatation for a usage example and more details
/// about this function.
#[inline]
pub fn get_timezone() -> std::result::Result<String, crate::GetTimezoneError> {
platform::get_timezone_inner()
}
Expand Down
7 changes: 1 addition & 6 deletions src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
pub fn get_timezone_inner() -> std::result::Result<String, crate::GetTimezoneError> {
Err(crate::GetTimezoneError::FailedParsingString)
Err(crate::GetTimezoneError::Unsupported)
}

compile_error!(
"iana-time-zone is currently implemented for Linux, Window, MacOS, FreeBSD, NetBSD, \
OpenBSD, Dragonfly, and WebAssembly (browser).",
);

0 comments on commit 03d1b3b

Please sign in to comment.