-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
110df51
commit f6f43d7
Showing
13 changed files
with
265 additions
and
39 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
32 changes: 32 additions & 0 deletions
32
emap-interchange/src/main/java/uk/ac/ucl/rits/inform/interchange/utils/DateTimeUtils.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 uk.ac.ucl.rits.inform.interchange.utils; | ||
|
||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
/** | ||
* Utility functions for manipulating timestamps etc. | ||
*/ | ||
public final class DateTimeUtils { | ||
private DateTimeUtils() {} | ||
|
||
/** | ||
* Round Instant to the nearest time unit using normal convention of halfway rounds up. | ||
* @param obsDatetime Instant to round | ||
* @param roundToUnit what ChronoUnit to round to, or null to return the original timestamp | ||
* @return the rounded Instant | ||
*/ | ||
public static Instant roundInstantToNearest(Instant obsDatetime, ChronoUnit roundToUnit) { | ||
if (roundToUnit == null) { | ||
return obsDatetime; | ||
} | ||
// determine whether to round up or down | ||
Instant roundedDown = obsDatetime.truncatedTo(roundToUnit); | ||
Instant roundedUp = obsDatetime.plus(1, roundToUnit).truncatedTo(roundToUnit); | ||
if (obsDatetime.until(roundedUp, ChronoUnit.NANOS) > roundedDown.until(obsDatetime, ChronoUnit.NANOS)) { | ||
return roundedDown; | ||
} else { | ||
return roundedUp; | ||
} | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
emap-interchange/src/main/java/uk/ac/ucl/rits/inform/interchange/utils/package-info.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,4 @@ | ||
/** | ||
* Utility code related to interchange messages, possibly quite loosely. | ||
*/ | ||
package uk.ac.ucl.rits.inform.interchange.utils; |
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
14 changes: 14 additions & 0 deletions
14
...orm-reader/src/main/java/uk/ac/ucl/rits/inform/datasources/waveform/SchedulingConfig.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,14 @@ | ||
package uk.ac.ucl.rits.inform.datasources.waveform; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
/** | ||
* Scheduling only to be enabled when not running unit tests. | ||
*/ | ||
@Configuration | ||
@EnableScheduling | ||
@Profile("!test") | ||
public class SchedulingConfig { | ||
} |
Oops, something went wrong.