use mf2_runtime::{Dir, FnContext, FormatError, Sink};
use crate::neutral::Neutral;
use crate::plan::{Backend, Plan};
#[derive(Clone, Copy, Default, Debug)]
pub struct Intl;
const MAX_MS: i64 = 8_640_000_000_000_000;
impl Backend for Intl {
fn supports(&self, _cx: &FnContext<'_>, plan: &Plan<'_>) -> Result<(), FormatError> {
if plan.request().epoch_ms.unsigned_abs() > MAX_MS.unsigned_abs() {
return Err(FormatError::UnsupportedOperation);
}
Ok(())
}
fn format(&self, cx: &FnContext<'_>, plan: &Plan<'_>, out: &mut dyn Sink) {
if !cx
.host()
.format_date_time(cx.locale(), &plan.request(), out)
{
Neutral.format(cx, plan, out);
}
}
fn dir(&self, cx: &FnContext<'_>, _plan: &Plan<'_>) -> Dir {
cx.catalog().dir()
}
}