-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bump: pogues-model to 1.4.2-SNAPSHOT * chore(Version): switch from Timestamp to ZonedDateTime * test: DateUtils (use in many cases) * chore: manage error when there is no result from db * feat: implementation of restoring version * chore: configure timeZone in props * bump: .9.5-SNAPSHOT * fix: owner missing (bump pogues-model to 1.4.2) * bump: 4.9.5-SNAPSHOT.1 * bump: 4.9.5
- Loading branch information
1 parent
a72d7d1
commit 759e081
Showing
13 changed files
with
153 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fr.insee.pogues.utils; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class DateUtils { | ||
|
||
public static ZoneId zoneId = ZoneId.systemDefault(); | ||
public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); | ||
|
||
/** | ||
* This function is used to get the date in ISO 8601 format Date | ||
* @param instant (can be null) | ||
* @return if date (Instant) is provided, it returns formated Date, if not returns formated of now. | ||
*/ | ||
public static String getIsoDateFromInstant(Instant instant){ | ||
if(instant != null) { | ||
return instant.atZone(zoneId).format(formatter); | ||
} | ||
ZonedDateTime zonedDateTimeNow = ZonedDateTime.now(zoneId); | ||
return zonedDateTimeNow.format(formatter); | ||
} | ||
|
||
public static Timestamp convertZonedDateTimeToTimestamp(ZonedDateTime zonedDateTime){ | ||
return Timestamp.from(zonedDateTime.toInstant()); | ||
} | ||
|
||
public static ZonedDateTime convertTimestampToZonedDateTime(Timestamp timestamp){ | ||
return timestamp.toInstant().atZone(ZoneId.systemDefault()); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package fr.insee.pogues.utils; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.*; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.TimeZone; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class DateUtilsTest { | ||
|
||
@BeforeEach | ||
void setup(){ | ||
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("Europe/Paris"))); | ||
} | ||
|
||
@Test | ||
void testConversionOfChristmasDate(){ | ||
ZonedDateTime zonedDateTime = ZonedDateTime.of( | ||
2024,12,25, | ||
20,45,50,0, | ||
ZoneId.systemDefault()); | ||
Instant instant = zonedDateTime.toInstant(); | ||
assertEquals("2024-12-25T20:45:50.000+0100", DateUtils.getIsoDateFromInstant(instant)); | ||
} | ||
|
||
@Test | ||
void timestampToZonedDateTime(){ | ||
String dateString = "2024-12-25 20:45:50"; | ||
Timestamp timestamp = Timestamp.valueOf(dateString); | ||
ZonedDateTime zonedDateTimeConverted = DateUtils.convertTimestampToZonedDateTime(timestamp); | ||
assertEquals(2024,zonedDateTimeConverted.getYear()); | ||
assertEquals(12,zonedDateTimeConverted.getMonthValue()); | ||
assertEquals(25,zonedDateTimeConverted.getDayOfMonth()); | ||
assertEquals(20, zonedDateTimeConverted.getHour()); | ||
assertEquals(45, zonedDateTimeConverted.getMinute()); | ||
assertEquals(50, zonedDateTimeConverted.getSecond()); | ||
} | ||
|
||
@Test | ||
void zonedDateTimeToTimestamp(){ | ||
ZonedDateTime zonedDateTime = ZonedDateTime.of( | ||
2024,12,25, | ||
20,45,50,0, | ||
ZoneId.systemDefault()); | ||
long longZone = zonedDateTime.toInstant().toEpochMilli(); | ||
Timestamp timestamp = DateUtils.convertZonedDateTimeToTimestamp(zonedDateTime); | ||
long longTimestamp = timestamp.getTime(); | ||
assertEquals(longZone, longTimestamp); | ||
} | ||
} |
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