Skip to main content

resolve_tz_with_default

Function resolve_tz_with_default 

Source
pub fn resolve_tz_with_default(
    own: Option<&str>,
    repo_default: Option<&str>,
) -> Tz
Expand description

Resolve a consuming cron’s own optional IANA timezone against a repository-level default, falling back to UTC (mirrors resolve_tz): own wins when set, else repo_default (typically Repository/ClusterRepository spec.scheduleDefaults.timezone), else UTC. An unparseable name at whichever level is selected falls back to UTC defensively, same as resolve_tz — the admission webhook rejects bad names up front for both levels via validate::validate_timezone, so reconcile-time resolution should never see one.

use kopiur_api::common::resolve_tz_with_default;

// The schedule's own timezone wins, even over a repo default.
assert_eq!(
    resolve_tz_with_default(Some("America/Chicago"), Some("UTC")),
    "America/Chicago".parse::<chrono_tz::Tz>().unwrap(),
);
// Absent own timezone falls through to the repo default.
assert_eq!(
    resolve_tz_with_default(None, Some("America/New_York")),
    "America/New_York".parse::<chrono_tz::Tz>().unwrap(),
);
// Both absent → UTC.
assert_eq!(resolve_tz_with_default(None, None), chrono_tz::Tz::UTC);