From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-widget-toolkit 2/2] plain date: add some useful methods
Date: Wed, 17 Dec 2025 11:30:11 +0100 [thread overview]
Message-ID: <20251217103017.1103164-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251217103017.1103164-1-d.csapak@proxmox.com>
these reuse the also new 'to_date' which can be handy if one needs to
work with javascript date objects.
In the future we should replace that with the equivalent temporal api
types.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/widget/form/date_field/plain_date.rs | 29 ++++++++++++++++++------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/widget/form/date_field/plain_date.rs b/src/widget/form/date_field/plain_date.rs
index e7d8a97..107c5f9 100644
--- a/src/widget/form/date_field/plain_date.rs
+++ b/src/widget/form/date_field/plain_date.rs
@@ -27,17 +27,32 @@ impl PlainDate {
}
}
+ /// Return a new [`js_sys::Date`] with a time value of 00:00:00.
+ pub fn to_date(&self) -> Date {
+ Date::new_with_year_month_day(self.year as u32, self.month as i32, self.day as i32)
+ }
+
/// Convert to a timestamp (milliseconds).
/// Returns the timestamp for 12:00:00 (Noon) local time on this date.
pub fn to_timestamp(&self) -> f64 {
- let d = Date::new_0();
- d.set_full_year(self.year as u32);
- d.set_month(self.month);
- d.set_date(self.day);
+ let d = self.to_date();
d.set_hours(12);
- d.set_minutes(0);
- d.set_seconds(0);
- d.set_milliseconds(0);
+ d.get_time()
+ }
+
+ /// Convert to a timestamp (milliseconds).
+ /// Returns the timestamp for 00:00:00 local time on this date.
+ pub fn to_timestamp_start(&self) -> f64 {
+ self.to_date().get_time()
+ }
+
+ /// Convert to a timestamp (milliseconds).
+ /// Returns the timestamp for 23:59:59 local time on this date.
+ pub fn to_timestamp_end(&self) -> f64 {
+ let d = self.to_date();
+ d.set_hours(23);
+ d.set_minutes(59);
+ d.set_seconds(59);
d.get_time()
}
--
2.47.3
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
next prev parent reply other threads:[~2025-12-17 10:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 10:30 [yew-devel] [PATCH yew-widget-toolkit 1/2] plain date: improve format parser Dominik Csapak
2025-12-17 10:30 ` Dominik Csapak [this message]
2025-12-17 11:31 ` [yew-devel] applied: " Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251217103017.1103164-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.