From a61e687d7e9bd14d8154f1c1d54dea8164209b65 Mon Sep 17 00:00:00 2001
From: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com>
Date: Sun, 10 Dec 2023 03:22:37 +0800
Subject: [PATCH] Feat/time library (#42)
* feat: change the time library to chrono
* fix: calendar demo
---
Cargo.toml | 2 +-
demo/src/pages/calendar/mod.rs | 17 +++--
src/calendar/mod.rs | 119 ++++++++++++++++-----------------
src/lib.rs | 1 +
4 files changed, 71 insertions(+), 68 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index e7c951a..380d248 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -38,7 +38,7 @@ icondata = { version = "0.1.0", features = [
icondata_core = "0.0.2"
uuid = { version = "1.5.0", features = ["v4"] }
cfg-if = "1.0.0"
-time = { version = "0.3.30", features = ["wasm-bindgen"] }
+chrono = "0.4.31"
[features]
default = ["csr"]
diff --git a/demo/src/pages/calendar/mod.rs b/demo/src/pages/calendar/mod.rs
index 01e2d2a..595a9c2 100644
--- a/demo/src/pages/calendar/mod.rs
+++ b/demo/src/pages/calendar/mod.rs
@@ -1,21 +1,24 @@
use crate::components::{Demo, DemoCode};
use leptos::*;
use prisms::highlight_str;
+use thaw::chrono::prelude::*;
use thaw::*;
#[component]
pub fn CalendarPage() -> impl IntoView {
- let value = create_rw_signal(OffsetDateTime::now_utc().date());
+ let value = create_rw_signal(Some(Local::now().date_naive()));
view! {
"Calendar"
-
+
{highlight_str!(
r#"
- let value = create_rw_singal(OffsetDateTime::now_utc().date());
+ use thaw::chrono::prelude::*;
+
+ let value = create_rw_signal(Some(Local::now().date_naive()));
view! {
@@ -39,8 +42,12 @@ pub fn CalendarPage() -> impl IntoView {
"value" |
- "RwSignal" |
- |
+
+ "RwSignal
+ |
+
+ "Default::deafult()"
+ |
|
diff --git a/src/calendar/mod.rs b/src/calendar/mod.rs
index 59da414..b3a300d 100644
--- a/src/calendar/mod.rs
+++ b/src/calendar/mod.rs
@@ -1,16 +1,19 @@
mod theme;
-use crate::{use_theme, utils::mount_style, Button, ButtonGroup, ButtonVariant, Theme};
+use crate::{
+ chrono::{Datelike, Days, Local, NaiveDate},
+ use_theme,
+ utils::mount_style,
+ Button, ButtonGroup, ButtonVariant, Theme,
+};
+use chrono::{Month, Months};
use icondata::AiIcon;
use leptos::*;
use std::ops::Deref;
pub use theme::CalendarTheme;
-pub use time::Date;
-use time::Month;
-pub use time::OffsetDateTime;
#[component]
-pub fn Calendar(#[prop(into)] value: RwSignal) -> impl IntoView {
+pub fn Calendar(#[prop(optional, into)] value: RwSignal
@@ -153,19 +166,20 @@ pub fn Calendar(#[prop(into)] value: RwSignal) -> impl IntoView {
}
#[component]
-fn CalendarItem(value: RwSignal, index: usize, date: CalendarItemDate) -> impl IntoView {
+fn CalendarItem(
+ value: RwSignal