Repository navigation
Start each new day at 12:00 CET instead of after 24 hours of uptime #262
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
Merged
+168
−47
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/net/tfminecraft/simplefactions/economy/settlement/NewDaySchedule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package net.tfminecraft.simplefactions.economy.settlement; | ||
|
|
||
| import java.time.Instant; | ||
| import java.time.LocalTime; | ||
| import java.time.ZoneId; | ||
| import java.time.ZonedDateTime; | ||
|
|
||
| /** | ||
| * A new day starts at noon CET (Europe/Paris, so CEST in summer) by the calendar, not after a | ||
| * day of server uptime: a crash or a lagging server no longer moves it. | ||
| */ | ||
| public final class NewDaySchedule { | ||
| public static final ZoneId ZONE = ZoneId.of("Europe/Paris"); | ||
| public static final LocalTime TIME = LocalTime.NOON; | ||
|
|
||
| private NewDaySchedule() {} | ||
|
|
||
| /** The latest new-day start at or before this instant, in epoch milliseconds. */ | ||
| public static long latestAtOrBefore(long millis) { | ||
| ZonedDateTime at = Instant.ofEpochMilli(millis).atZone(ZONE); | ||
| ZonedDateTime start = at.toLocalDate().atTime(TIME).atZone(ZONE); | ||
| return (start.isAfter(at) ? start.minusDays(1) : start).toInstant().toEpochMilli(); | ||
| } | ||
|
|
||
| /** The first new-day start after this instant, in epoch milliseconds. */ | ||
| public static long nextAfter(long millis) { | ||
| // plusDays keeps noon local time across a daylight saving change. | ||
| return Instant.ofEpochMilli(latestAtOrBefore(millis)).atZone(ZONE).plusDays(1).toInstant().toEpochMilli(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/test/java/net/tfminecraft/simplefactions/economy/settlement/NewDayScheduleTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package net.tfminecraft.simplefactions.economy.settlement; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import java.time.Instant; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class NewDayScheduleTest { | ||
| private static long at(String instant) { | ||
| return Instant.parse(instant).toEpochMilli(); | ||
| } | ||
|
|
||
| @Test void aNewDayStartsAtNoonCetInWinter() { | ||
| assertEquals(at("2026-12-01T11:00:00Z"), NewDaySchedule.latestAtOrBefore(at("2026-12-02T10:59:59.999Z"))); | ||
| assertEquals(at("2026-12-02T11:00:00Z"), NewDaySchedule.latestAtOrBefore(at("2026-12-02T11:00:00Z"))); | ||
| assertEquals(at("2026-12-02T11:00:00Z"), NewDaySchedule.nextAfter(at("2026-12-01T22:54:03Z"))); | ||
| assertEquals(at("2026-12-03T11:00:00Z"), NewDaySchedule.nextAfter(at("2026-12-02T11:00:00Z"))); | ||
| } | ||
|
|
||
| @Test void aNewDayStartsAtNoonCestInSummerAndAcrossTheClockChange() { | ||
| assertEquals(at("2026-07-01T10:00:00Z"), NewDaySchedule.latestAtOrBefore(at("2026-07-01T10:30:00Z"))); | ||
| // Clocks go forward on 2026-03-29: noon CET, then noon CEST 23 hours later. | ||
| assertEquals(at("2026-03-29T10:00:00Z"), NewDaySchedule.nextAfter(at("2026-03-28T11:00:00Z"))); | ||
| // Clocks go back on 2026-10-25: noon CEST, then noon CET 25 hours later. | ||
| assertEquals(at("2026-10-25T11:00:00Z"), NewDaySchedule.nextAfter(at("2026-10-24T10:00:00Z"))); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.