Class JobTimestamp

java.lang.Object
com.kazurayam.materialstore.core.JobTimestamp
All Implemented Interfaces:
Jsonifiable, Comparable<JobTimestamp>

public final class JobTimestamp extends Object implements Comparable<JobTimestamp>, Jsonifiable
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 Details

  • Constructor Details

    • JobTimestamp

      public JobTimestamp(String jobTimestamp)
      Sole constructor
      Parameters:
      jobTimestamp - yyyymmdd_hhMMss e.g. "20210718_091328"; or "_"
  • Method Details

    • isValid

      public static boolean isValid(String s)
      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

      public static JobTimestamp now()
      Returns:
      an instance of JobTimestamp with the value of java.time.LocalDateTime.now()
    • create

      public static JobTimestamp create(LocalDateTime theTimestamp)
      Parameters:
      theTimestamp - a JobTimestamp to copy
      Returns:
      a new JobTimestamp with value of theTimestamp as LocalDateTime
    • epoch

      public static JobTimestamp epoch()
      Returns:
      a special instance of JobName of which value is a String "_" (under-bar).
    • max

      public static JobTimestamp max(JobTimestamp... timestamps)
      Parameters:
      timestamps - a list of JobTimestamps to look at
      Returns:
      the newest JobTimestamp value among the given timestamps
    • laterThan

      public static JobTimestamp laterThan(JobTimestamp... previous)
      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

      public 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. 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 basis
      theTime - a JobTimestamp
      Returns:
      a new JobTimestamp value which is assured to be newer thanThis at least for 1 second or more.
    • betweenSeconds

      public static long betweenSeconds(JobTimestamp previous, JobTimestamp following)
      calculate the time distance between following and previous in seconds.
      Parameters:
      previous - e.g, 20221123_080000
      following - e.g, 20221123_080130
      Returns:
      the seconds between the following minus the previous. E.g, (20221123_080130 - 20221123_080000) should return 90.
    • minus

      public JobTimestamp minus(long amountToSubtract, TemporalUnit unit)
    • minusDays

      public JobTimestamp minusDays(long days)
      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

      public JobTimestamp minusHours(long hours)
      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

      public JobTimestamp minusMinutes(long minutes)
      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

      public JobTimestamp minusMonths(long months)
      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

      public JobTimestamp minusSeconds(long seconds)
      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

      public JobTimestamp minusWeeks(long weeks)
      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

      public JobTimestamp plus(long amountToAdd, TemporalUnit unit)
    • plusDays

      public JobTimestamp plusDays(long days)
      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

      public JobTimestamp plusHours(long hours)
      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

      public JobTimestamp plusMinutes(long minutes)
      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

      public JobTimestamp plusMonths(long months)
      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

      public JobTimestamp plusSeconds(long seconds)
      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

      public JobTimestamp plusWeeks(long weeks)
      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

      public JobTimestamp withSecond(int second)
      Parameters:
      second - 0..59
      Returns:
      a copy of this JobTimestamp instance but with the given second value
    • withMinute

      public JobTimestamp withMinute(int minute)
      Parameters:
      minute - 0..59
      Returns:
      a copy of this JobTimestamp instance but with the given minute value
    • withHour

      public JobTimestamp withHour(int hour)
      Parameters:
      hour - 0..23
      Returns:
      a copy of this JobTimestamp instance but with the given hour value
    • beginningOfTheMonth

      public JobTimestamp 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

      public JobTimestamp 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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      E.g, 20221129_195423 represents the year 2022, the month 11, the day 29, the hours 19, the minutes 54, the second 23.
      Overrides:
      toString in class Object
    • toJson

      public String toJson()
      Specified by:
      toJson in interface Jsonifiable
      Returns:
      "20221129_195423" enclosed by double-quotes
    • toJson

      public String toJson(boolean prettyPrint)
      Specified by:
      toJson in interface Jsonifiable
    • value

      public LocalDateTime 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

      public int compareTo(JobTimestamp other)
      Specified by:
      compareTo in interface Comparable<JobTimestamp>