-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Implement TemporalAdjusters or similar mechanism #20
Comments
Hi, you can subtract a week with I'll happily accept a PR for this; however, you don't necessarily have to do it the Java way, you may just add a |
I try to stick to the ThreeTen API since this is the base of the project. This is to keep the API consistent with other ThreeTen backports like JS Joda as well. But if you feel this is going to be too cumbersome, let me know. |
TBH this library has already deviated a bit from ThreeTen (for better of for worse), and I'm not sure whether I want to continue walking in their footsteps. For now, I'd accept a PR with only the method in question. If there's a plan to stick to the Threeten API, we can still do it later, there will be a BC break anyway. I do like the foundation layed by Threeten, however I feel like their API is a bit bloated, and this particular use case "give me the previous monday" is a good example IMO. What else can TemporalAdjusters do, exactly? |
A Since this is a lambda, you may create a more complex TemporalAdjuster previousMondayAdjuster = (Temporal baseT) -> {
Temporal previousWeekT = baseT.minus(Period.ofDays(7));
Temporal previousMondayT = previousWeekT.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
return previousMondayT;
}; The use site then ends up like this: LocalDate nowDate = LocalDate.now();
LocalDate previousMondayDate = nowDate.with(previousMondayAdjuster); It is basically a way to allow developers to create custom manipulation "methods". Rather than fixing a set of methods like:
You only give one But you got a point since simple operations like "substract one week" do have utility methods ( Note: Anyway, I will dig into the subject a little more. I will post additional feedbacks as to "why |
This is interesting, although I'm still not sure if I see a value for now. First of all, I can see an issue with returning a generic And, what's the point of creating your own Adjuster: class FirstMondayAdjuster implements TemporalAdjuster {
...
}
$adjuster = new FirstMondayAdjuster();
$adjustedDate = $localDate->with($adjuster); ...when you can just create a class that does adjustments directly? class Adjuster {
public function firstMonday(LocalDate $localDate) : LocalDate {
...
}
}
$adjuster = new Adjuster();
$adjustedDate = $adjuster->firstMonday($localDate);
I'd be happy with |
I believe he wants the equivalent of https://www.php.net/manual/en/datetime.modify.php except not a string modifier but more advanced. PHP does not support callback type hinting though (yet), so that would be a small problem... |
Stop me if I'm wrong, but there is no simple, built-in way to do operations like the following in
Carbon
:The ThreeTen way is the use of
TemporalAdjuster
:If it is OK, I would like to investigate and if possible (most likely) implement the ThreeTen way.
The text was updated successfully, but these errors were encountered: