-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#654] Get week start and end days #666
Conversation
Thanks for working on this! I think I suggested to make these |
Regarding:
Sorry, I was about to leave a message explaining why I choose a
What do you think? |
That makes sense to me, thanks for explaining your position in more detail! |
f76fa06
to
4c7e6df
Compare
@djc I think this PR is finally ready for a full review. Would you mind taking a look at it, please? |
The implementation of |
7ddf118
to
38fdb29
Compare
The issue reported by the CI was fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in reviewing this -- I was on holiday yesterday.
I think it mostly looks good, but I have some feedback to consider.
src/lib.rs
Outdated
@@ -450,13 +448,15 @@ pub mod prelude { | |||
#[doc(no_inline)] | |||
pub use crate::SubsecRound; | |||
#[doc(no_inline)] | |||
pub use crate::{Date, Week}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these need to be added to the prelude, since they're relatively niche.
src/traits.rs
Outdated
/// [start_day]: ./trait.Weeklike.html#tymethod.start_day | ||
/// [end_day]: ./trait.Weeklike.html#method.end_day | ||
#[inline] | ||
fn range(&self) -> RangeInclusive<Self::Day> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer to call this days()
to make it clear what the range's Item
is. What do you think?
src/naive/date.rs
Outdated
#[derive(Debug)] | ||
pub struct NaiveWeek { | ||
date: NaiveDate, | ||
weekday: Weekday, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think weekday
should be called start
, as that is the intended role within the type (as far as I understand).
src/naive/date.rs
Outdated
|
||
#[inline] | ||
fn start_day(&self) -> Self::Day { | ||
let start = self.date.weekday().num_days_from_monday() as i64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could calculate this in u8
, right? Why are we casting here?
src/naive/date.rs
Outdated
let start = self.date.weekday().num_days_from_monday() as i64; | ||
let end = self.weekday.num_days_from_monday() as i64; | ||
let days = start - end; | ||
self.date - Duration::days(if days >= 0 { days } else { 7 + days }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if days >= 0 { days } else { 7 + days }
could be more naturally expressed with some kind of modulo?
785dd1c
to
b274146
Compare
0f9f5ba
to
b8d99d7
Compare
src/date.rs
Outdated
use crate::DateTime; | ||
use crate::{Datelike, Weekday}; | ||
|
||
/// A week represented by a [`NaiveWeek`] + [Offset](crate::offset::Offset). | ||
#[derive(Debug)] | ||
pub struct Week<Tz: TimeZone> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, after reviewing some other PRs I'm on the fence about this concept of types that don't point to a specific time but do reference a timezone. Since the type represents a time span, the timezone offset could conceivably be different at the start of the span vs the end of the span, which we cannot represent accurately.
How important is having this type included to you? Could we make do with just the NaiveWeek
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@djc - It makes sense to me, starting with NaiveWeek
sounds fair. I just updated the PR simplifying the implementation a little bit.
502df87
to
725e6d9
Compare
Pushed a PR addressing the error reported by the linter: > cargo fmt -- --check --color=always && echo "OK"
OK |
Still some doc link issues, can you check that out? |
Co-authored-by: David Mazarro <dmunuera@stackbuilders.com> Co-authored-by: Jorge Guerra <jguerra@stackbuilders.com>
725e6d9
to
f4f73f6
Compare
Hopefully, everything turns green this time 🤞🏼
|
Thanks for seeing this through! |
Thank you for all the feedback and time spent on this PR |
Closes #654 |
Thanks for contributing to chrono!
about adding the PR number)
we can't reintroduce it?