display time until opening/closing

This commit is contained in:
insects 2025-02-05 20:57:43 +01:00
parent 3c935a1be3
commit e04a98a7fd
5 changed files with 60 additions and 5 deletions

View file

@ -1,7 +1,9 @@
use std::collections::HashMap;
use chrono::{DateTime, Datelike, Duration, Timelike, Utc};
use chrono_humanize::HumanTime;
use serde::{Deserialize, Serialize};
use serde_json::map::Entry;
use crate::{
clock,
@ -104,6 +106,19 @@ pub struct Window {
pub duration: Duration,
}
impl Window {
pub fn display_end_time(&self) -> String {
let end_date = self.start_time + self.duration;
let human_date = HumanTime::from(clock::to_earth_time(end_date));
format!("{}", human_date)
}
pub fn display_start_time(&self) -> String {
let human_date = HumanTime::from(clock::to_earth_time(self.start_time));
format!("{}", human_date)
}
}
#[allow(clippy::needless_lifetimes)]
impl<'a> CombinedFish<'a> {
/// Fills in the rest of the struct.

View file

@ -1,6 +1,7 @@
use std::sync::Arc;
use std::{cmp::Ordering, sync::Arc};
use axum::extract::State;
use chrono::Duration;
use maud::{html, Markup, DOCTYPE};
use crate::{clock, data::CombinedFish, AppState};
@ -35,13 +36,22 @@ pub fn main_page(state: State<Arc<AppState>>, with_layout: bool) -> Markup {
let template = html! {
h1 { "Hello! Current ET: " (clock::get_current_eorzea_date().format("%H:%M")) }
@for fish in values {
section.up[fish.is_up || fish.is_always_up] {
section.up[fish.is_up || fish.is_always_up].alwaysup[fish.is_always_up] {
.title {
h3 { (fish.meta.name_en) }
.subtitle {
"Patch " (fish.entry.patch)
}
}
.when {
@if let Some(window) = fish.windows.first() {
@if fish.is_up || fish.is_always_up {
"closes " (window.display_end_time())
} @else {
"opens " (window.display_start_time())
}
}
}
.meta {
@if fish.entry.start_hour.is_some() && fish.entry.end_hour.is_some() {
div {