use crate::*;
use ::time::format_description;
use ::time::{Date, OffsetDateTime, PrimitiveDateTime, Time};
use leptos::prelude::*;
#[derive(Clone, Default)]
pub struct RenderTimeOptions {
pub string: Option<String>,
}
impl CellValue<Date> for Date {
type RenderOptions = RenderTimeOptions;
fn render_value(self, options: Self::RenderOptions) -> impl IntoView {
if let Some(value) = options.string.as_ref() {
let format = format_description::parse(value)
.expect("Unable to construct a format description given the format string");
self.format(&format)
.expect("Unable to format given the format description")
} else {
self.to_string()
}
}
}
impl CellValue<Time> for Time {
type RenderOptions = RenderTimeOptions;
fn render_value(self, options: Self::RenderOptions) -> impl IntoView {
if let Some(value) = options.string.as_ref() {
let format = format_description::parse(value)
.expect("Unable to construct a format description given the format string");
self.format(&format)
.expect("Unable to format given the format description")
} else {
self.to_string()
}
}
}
impl CellValue<PrimitiveDateTime> for PrimitiveDateTime {
type RenderOptions = RenderTimeOptions;
fn render_value(self, options: Self::RenderOptions) -> impl IntoView {
if let Some(value) = options.string.as_ref() {
let format = format_description::parse(value)
.expect("Unable to construct a format description given the format string");
self.format(&format)
.expect("Unable to format given the format description")
} else {
self.to_string()
}
}
}
impl CellValue<OffsetDateTime> for OffsetDateTime {
type RenderOptions = RenderTimeOptions;
fn render_value(self, options: Self::RenderOptions) -> impl IntoView {
if let Some(value) = options.string.as_ref() {
let format = format_description::parse(value)
.expect("Unable to construct a format description given the format string");
self.format(&format)
.expect("Unable to format given the format description")
} else {
self.to_string()
}
}
}