Package com.kazurayam.materialstore.core
Class JobTimestamp
java.lang.Object
com.kazurayam.materialstore.core.JobTimestamp
- All Implemented Interfaces:
Jsonifiable
,Comparable<JobTimestamp>
JobTimestamp wraps an instance of java.time.LocalDateTime and
associates a fixed instance of java.time.format.DateTimeFormatter to be used.
The DateTimeFormat uses a format "uuuuMMdd_HHmmss".
The toString() method will return a String, for example, "20221129_110345".
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
special value that represents a NULL object.static final DateTimeFormatter
static final JobTimestamp
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
betweenSeconds
(JobTimestamp previous, JobTimestamp following) calculate the time distance between following and previous in seconds.int
compareTo
(JobTimestamp other) static JobTimestamp
create
(LocalDateTime theTimestamp) static JobTimestamp
epoch()
boolean
int
hashCode()
static boolean
verifies if the given string is in the format of the FORMATTER, and returns true or false.static JobTimestamp
laterThan
(JobTimestamp... previous) static JobTimestamp
max
(JobTimestamp... timestamps) minus
(long amountToSubtract, TemporalUnit unit) minusDays
(long days) minusHours
(long hours) minusMinutes
(long minutes) minusMonths
(long months) minusSeconds
(long seconds) minusWeeks
(long weeks) static JobTimestamp
now()
plus
(long amountToAdd, TemporalUnit unit) plusDays
(long days) plusHours
(long hours) plusMinutes
(long minutes) plusMonths
(long months) plusSeconds
(long seconds) plusWeeks
(long weeks) static JobTimestamp
theTimeOrLaterThan
(JobTimestamp thanThis, JobTimestamp theTime) When thanThis is "20221130_010101" and theTime is "20221130_010105", then a JobTimestamp of "20221130_010105" will be returned.toJson()
toJson
(boolean prettyPrint) toString()
E.g, 20221129_195423 represents the year 2022, the month 11, the day 29, the hours 19, the minutes 54, the second 23.value()
If the value is the special "_", then LocalDateTime.ofEpochSecond(0L, 0, ZoneOffset.UTC) will be returnedwithHour
(int hour) withMinute
(int minute) withSecond
(int second)
-
Field Details
-
EPOCH_NAME
special value that represents a NULL object.- See Also:
-
NULL_OBJECT
-
FORMATTER
-
-
Constructor Details
-
JobTimestamp
Sole constructor- Parameters:
jobTimestamp
- yyyymmdd_hhMMss e.g. "20210718_091328"; or "_"
-
-
Method Details
-
isValid
verifies if the given string is in the format of the FORMATTER, and returns true or false. A under-bar "_" is accepted as the only exception, which stands for the case where no concrete JobTimestamp is given.- Parameters:
s
- for example, "20221123_094521"- Returns:
- true if the s is in a valid format as JobTimestamp. otherwise false.
-
now
- Returns:
- an instance of JobTimestamp with the value of java.time.LocalDateTime.now()
-
create
- Parameters:
theTimestamp
- a JobTimestamp to copy- Returns:
- a new JobTimestamp with value of theTimestamp as LocalDateTime
-
epoch
- Returns:
- a special instance of JobName of which value is a String "_" (under-bar).
-
max
- Parameters:
timestamps
- a list of JobTimestamps to look at- Returns:
- the newest JobTimestamp value among the given timestamps
-
laterThan
- Parameters:
previous
- a list of JobTimestamps as comparison basis- Returns:
- a new JobTimestamp value which is assured to be newer than any of previous JobTimestamps. If JobTimestamp.now() is newer than them, then the value of JobTimestamp.now() will be returned. If JobTimestamp.now() is equal to the maximum of previous timestamp, the max value will be returned.
-
theTimeOrLaterThan
When thanThis is "20221130_010101" and theTime is "20221130_010105", then a JobTimestamp of "20221130_010105" will be returned. When thanThis is "20221130_010101" and theTime is "20221130_010100", then a JobTimestamp of "20221130_010102", which is equal to (thanThis + 1 second), will be returned. When thanThis is "20221130_010101" and theTime is "20221130_010101", then a JobTimestamp of "20221130_010101" will be returned.- Parameters:
thanThis
- a JobTimestamp as basistheTime
- a JobTimestamp- Returns:
- a new JobTimestamp value which is assured to be newer thanThis at least for 1 second or more.
-
betweenSeconds
calculate the time distance between following and previous in seconds.- Parameters:
previous
- e.g, 20221123_080000following
- e.g, 20221123_080130- Returns:
- the seconds between the following minus the previous. E.g, (20221123_080130 - 20221123_080000) should return 90.
-
minus
-
minusDays
- Parameters:
days
- number of days backward. E.g, 3 days.- Returns:
- a new JobTimestamp instance with the value which is "days" before this JobTimestamp instance.
-
minusHours
- Parameters:
hours
- number of hours backward. E.g, 5 hours.- Returns:
- a new JobTimestamp instance with the value which is "hours" before this JobTimestamp instance.
-
minusMinutes
- Parameters:
minutes
- number of minutes backward. E.g, 4 minutes.- Returns:
- a new JobTimestamp instance with the value which is "minutes" before this JobTimestamp instance.
-
minusMonths
- Parameters:
months
- nuber of months back. E.g, 2 months.- Returns:
- a new JobTimestamp instance with the value which is "months" before this JobTimestamp instance.
-
minusSeconds
- Parameters:
seconds
- number of seconds back. E.g, 10 seconds.- Returns:
- a new JobTimestamp instance with the value which is "seconds" before this JobTimestamp instance.
-
minusWeeks
- Parameters:
weeks
- number of weeks back. E.g, 3 weeks.- Returns:
- a new JobTimestamp instance with the value which is "weeks" before this JobTimestamp instance.
-
plus
-
plusDays
- Parameters:
days
- number of days ahead. E.g, 2 days.- Returns:
- a new JobTimestamp instance with the value which is "days" after this JobTimestamp instance.
-
plusHours
- Parameters:
hours
- number of hours ahead. E.g, 3 hours.- Returns:
- a new JobTimestamp instance with the value which is "hours" after this JobTimestamp instance.
-
plusMinutes
- Parameters:
minutes
- number of minutes ahead. E.g, 2 minutes- Returns:
- a new JobTimestamp instance with the value which is "minutes" after this JobTimestamp instance.
-
plusMonths
- Parameters:
months
- number of months ahead. E.g, 2 months- Returns:
- a new JobTimestamp instance with the value which is "months" after this JobTimestamp instance.
-
plusSeconds
- Parameters:
seconds
- number of seconds ahead. E.g, 5 seconds.- Returns:
- a new JobTimestamp instance with the value which is "seconds" after this JobTimestamp instance.
-
plusWeeks
- Parameters:
weeks
- number of weeks ahead. E.g, 3 weeks- Returns:
- a new JobTimestamp instance with the value which is "weeks" after this JobTimestamp instance.
-
withSecond
- Parameters:
second
- 0..59- Returns:
- a copy of this JobTimestamp instance but with the given second value
-
withMinute
- Parameters:
minute
- 0..59- Returns:
- a copy of this JobTimestamp instance but with the given minute value
-
withHour
- Parameters:
hour
- 0..23- Returns:
- a copy of this JobTimestamp instance but with the given hour value
-
beginningOfTheMonth
- Returns:
- a new JobTimestamp instance with the value which is the beginning of the month in which this JobTimestamp instance belongs. The hours will be 00, the minutes will be 00, the seconds will be 00.
-
endOfTheMonth
- Returns:
- a new JobTimestamp instance with the value which is the last day of the month in which this JobTimestamp instance belongs. The hours will be 23, the minutes will be 59, the seconds will be 59.
-
equals
-
hashCode
public int hashCode() -
toString
E.g, 20221129_195423 represents the year 2022, the month 11, the day 29, the hours 19, the minutes 54, the second 23. -
toJson
- Specified by:
toJson
in interfaceJsonifiable
- Returns:
- "20221129_195423" enclosed by double-quotes
-
toJson
- Specified by:
toJson
in interfaceJsonifiable
-
value
If the value is the special "_", then LocalDateTime.ofEpochSecond(0L, 0, ZoneOffset.UTC) will be returned- Returns:
- the LocalDateTime value of this instance
-
compareTo
- Specified by:
compareTo
in interfaceComparable<JobTimestamp>
-