-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New utility methods for Date and removed workflows (#9)
* Added new utility methods in DateUtils * Added new utility methods for DateUtils * Deleted CodeQL and Maven Publish workflows
- Loading branch information
1 parent
ee08c56
commit 349fc01
Showing
5 changed files
with
209 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
primekit-essentials/src/main/java/com/shortthirdman/primekit/essentials/common/YearWeek.java
This file contains 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,32 @@ | ||
package com.shortthirdman.primekit.essentials.common; | ||
|
||
import java.text.MessageFormat; | ||
import java.time.DateTimeException; | ||
import java.time.LocalDate; | ||
import java.time.chrono.Chronology; | ||
import java.time.chrono.IsoChronology; | ||
import java.time.temporal.ChronoField; | ||
import java.time.temporal.TemporalAccessor; | ||
import java.util.Objects; | ||
|
||
|
||
public record YearWeek(int year, int week) { | ||
|
||
public static YearWeek from(TemporalAccessor temporal) { | ||
Objects.requireNonNull(temporal, "temporal"); | ||
try { | ||
if (!IsoChronology.INSTANCE.equals(Chronology.from(temporal))) { | ||
temporal = LocalDate.from(temporal); | ||
} | ||
return new YearWeek(temporal.get(ChronoField.YEAR), temporal.get(ChronoField.ALIGNED_WEEK_OF_YEAR)); | ||
} catch (DateTimeException ex) { | ||
String mf = MessageFormat.format("Unable to obtain YearWeek from TemporalAccessor: {0} of type {1}", temporal, temporal.getClass().getName()); | ||
throw new DateTimeException(mf, ex); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MessageFormat.format("{0}-{1}", year, week); | ||
} | ||
} |
This file contains 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 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