1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: MIT
3
4use crate::ui::*;
5use chrono::prelude::*;
6use slint::*;
7
8pub fn setup(window: &MainWindow) -> Timer {
9 let update_timer: Timer = Timer::default();
10 update_timer.start(mode:slint::TimerMode::Repeated, interval:std::time::Duration::from_millis(300), {
11 let weak_window: Weak = window.as_weak();
12
13 move || {
14 update(&weak_window.unwrap().global::<HeaderAdapter>());
15 }
16 });
17
18 update_timer
19}
20
21fn update(header_adapter: &HeaderAdapter) {
22 let now: DateTime = Local::now();
23
24 header_adapter.set_date(slint::format!("{}", now.format("%A %e %B %Y")));
25 header_adapter.set_time(slint::format!("{}", now.format("%I:%M")));
26 header_adapter.set_time_suffix(slint::format!("{}", now.format("%p")));
27}
28