Package net.time4j

Class PlainTimestamp

All Implemented Interfaces:
Serializable, Comparable<PlainTimestamp>, TemporalAccessor, GregorianDate, WallTime, ChronoDisplay, Normalizer<IsoUnit>, Temporal<PlainTimestamp>, ThreetenAdapter, LocalizedPatternSupport

Represents a plain composition of calendar date and wall time as defined in ISO-8601, but without any timezone.

Following elements which are declared as constants are registered by this class:

Furthermore, all elements of class Weekmodel are supported. As timestamp units can be used: CalendarUnit and ClockUnit.

Note: The special time value 24:00 is only supported in the factory methods which normalize the resulting timestamp to midnight of the following day. In element access and manipulations this value is not supported.

Author:
Meno Hochschild
See Also:
Serialized Form
  • Method Details

    • of

      public static PlainTimestamp of(PlainDate date, PlainTime time)

      Creates a new local timestamp with calendar date and wall time.

      The special time value 24:00 will automatically normalized such that the resulting timestamp is on starting midnight of following day.

      Parameters:
      date - calendar date component
      time - wall time component (24:00 will always be normalized)
      Returns:
      timestamp as composition of date and time
      See Also:
      of(int, int, int, int, int), of(int, int, int, int, int, int)
    • of

      public static PlainTimestamp of(int year, int month, int dayOfMonth, int hour, int minute)

      Creates a new local timestamp in minute precision.

      The special time value 24:00 will automatically normalized such that the resulting timestamp is on starting midnight of following day.

      Parameters:
      year - proleptic iso year [(-999,999,999)-999,999,999]
      month - gregorian month in range (1-12)
      dayOfMonth - day of month in range (1-31)
      hour - hour in the range 0-23 or 24 if minute and second are equal to 0
      minute - minute in the range 0-59
      Returns:
      timestamp as composition of date and time
    • of

      public static PlainTimestamp of(int year, int month, int dayOfMonth, int hour, int minute, int second)

      Creates a new local timestamp in second precision.

      The special time value 24:00 will automatically normalized such that the resulting timestamp is on starting midnight of following day.

      Parameters:
      year - proleptic iso year [(-999,999,999)-999,999,999]
      month - gregorian month in range (1-12)
      dayOfMonth - day of month in range (1-31)
      hour - hour in the range 0-23 or 24 if minute and second are equal to 0
      minute - minute in the range 0-59
      second - second in the range 0-59
      Returns:
      timestamp as composition of date and time
    • nowInSystemTime

      public static PlainTimestamp nowInSystemTime()

      Obtains the current timestamp in system time.

      Convenient short-cut for: SystemClock.inLocalView().now().

      Returns:
      current timestamp (without zone) in system time zone using the system clock
      Since:
      3.23/4.19
      See Also:
      SystemClock.inLocalView(), ZonalClock.now()
    • from

      public static PlainTimestamp from(LocalDateTime ldt)

      Short cut for TemporalType.LOCAL_DATE_TIME.translate(ldt).

      Parameters:
      ldt - Threeten-equivalent of this instance
      Returns:
      PlainTimestamp
      Since:
      4.0
      See Also:
      TemporalType.LOCAL_DATE_TIME
    • getCalendarDate

      public PlainDate getCalendarDate()

      Provides the calendar date part.

      Returns:
      calendar date component
    • getWallTime

      public PlainTime getWallTime()

      Provides the wall time part.

      Returns:
      wall time component
    • getYear

      public int getYear()
      Description copied from interface: GregorianDate

      Yields the proleptic year according to ISO-8601.

      The term proleptic means that the gregorian calendar rules are applied backwards even before the introduction of this calendar. Second: The year numbering is just the mathematical one as defined in ISO-8601 such that there is a year zero and even negative years: -2 = BC 3, -1 = BC 2, 0 = BC 1, 1 = AD 1, 2 = AD 2, ...

      Specified by:
      getYear in interface GregorianDate
      Returns:
      proleptic iso year in range GregorianMath.MIN_YEAR - GregorianMath.MAX_YEAR
    • getMonth

      public int getMonth()
      Description copied from interface: GregorianDate

      Yields the gregorian month as integer.

      Specified by:
      getMonth in interface GregorianDate
      Returns:
      gregorian month in range (1 = January, ..., 12 = December)
    • getDayOfMonth

      public int getDayOfMonth()
      Description copied from interface: GregorianDate

      Yields the day of month.

      Specified by:
      getDayOfMonth in interface GregorianDate
      Returns:
      day of month in range 1 <= dayOfMonth <= 31
    • getHour

      public int getHour()
      Description copied from interface: WallTime

      Yields the hour of day.

      Specified by:
      getHour in interface WallTime
      Returns:
      hour in range 0 - 24 (the value 24 is only allowed if minute and second have the value 0)
    • getMinute

      public int getMinute()
      Description copied from interface: WallTime

      Yields the minute of hour.

      Specified by:
      getMinute in interface WallTime
      Returns:
      minute in range 0 - 59
    • getSecond

      public int getSecond()
      Description copied from interface: WallTime

      Yields the second of minute.

      Given this context and the fact that this interface describes an analogue clock without UTC reference, the special leapsecond value 60 cannot be supported.

      Specified by:
      getSecond in interface WallTime
      Returns:
      second in range 0 - 59
    • getNanosecond

      public int getNanosecond()
      Description copied from interface: WallTime

      Yields the nanosecond.

      Implementations which are not capable of nanosecond precision will just yield 0 or another suitable rounded value.

      Specified by:
      getNanosecond in interface WallTime
      Returns:
      nanosecond in range 0 - 999,999,999
    • with

      public PlainTimestamp with(ElementOperator<?> operator)

      Adjusts this timestamp by given operator.

      Parameters:
      operator - element-related operator
      Returns:
      changed copy of this timestamp
      See Also:
      ChronoEntity.with(net.time4j.engine.ChronoOperator)
    • with

      public PlainTimestamp with(PlainDate date)

      Adjusts the calendar part of this timestamp.

      Parameters:
      date - new calendar date component
      Returns:
      changed copy of this timestamp
      See Also:
      PlainDate.COMPONENT
    • with

      public PlainTimestamp with(PlainTime time)

      Adjusts the wall time part of this timestamp.

      Parameters:
      time - new wall time component
      Returns:
      changed copy of this timestamp
      See Also:
      PlainTime.COMPONENT
    • isBefore

      public boolean isBefore(PlainTimestamp timestamp)
      Description copied from interface: Temporal

      Queries if this object is before given object on a timeline.

      Specified by:
      isBefore in interface Temporal<PlainTimestamp>
      Parameters:
      timestamp - object this instance is compared to
      Returns:
      true if this instance is temporally before temporal else false
    • isAfter

      public boolean isAfter(PlainTimestamp timestamp)
      Description copied from interface: Temporal

      Queries if this object is after given object on a timeline.

      Specified by:
      isAfter in interface Temporal<PlainTimestamp>
      Parameters:
      timestamp - object this instance is compared to
      Returns:
      true if this instance is temporally after temporal else false
    • isSimultaneous

      public boolean isSimultaneous(PlainTimestamp timestamp)
      Description copied from interface: Temporal

      Queries if this object and given object have the same position on the time axis.

      Is equivalent to !isAfter(temporal) && !isBefore(temporal). This method differs from the Object-method equals() such that first the comparison type must be a temporal one and second that only temporal-only state will be considered.

      Specified by:
      isSimultaneous in interface Temporal<PlainTimestamp>
      Parameters:
      timestamp - object this instance is compared to
      Returns:
      true if this instance is temporally equal to temporal else false
    • compareTo

      public int compareTo(PlainTimestamp timestamp)

      Defines the temporal order of date and time as natural order.

      The comparison is consistent with equals().

      Specified by:
      compareTo in interface Comparable<PlainTimestamp>
      Specified by:
      compareTo in class TimePoint<IsoUnit,​PlainTimestamp>
      See Also:
      isBefore(PlainTimestamp), isAfter(PlainTimestamp)
    • equals

      public boolean equals(Object obj)
      Description copied from class: TimePoint

      Compares the whole state of this instance with given object.

      Implementations will usually define their state only based on the temporal position on the time axis because this is the most intuitive approach. Exceptions from this rule should be explicitly documented and reasoned.

      Specified by:
      equals in class TimePoint<IsoUnit,​PlainTimestamp>
      See Also:
      TimePoint.compareTo(TimePoint)
    • hashCode

      public int hashCode()
      Description copied from class: TimePoint

      Subclasses must redefine this method corresponding to the behaviour of equals().

      Specified by:
      hashCode in class TimePoint<IsoUnit,​PlainTimestamp>
    • toString

      public String toString()

      Creates a canonical representation of the form "yyyy-MM-dd'T'HH:mm:ss,fffffffff".

      Dependent on the precision (that is last non-zero part of time) the time representation might be shorter.

      Specified by:
      toString in interface GregorianDate
      Specified by:
      toString in interface WallTime
      Specified by:
      toString in class TimePoint<IsoUnit,​PlainTimestamp>
      Returns:
      canonical ISO-8601-formatted string
      See Also:
      PlainTime.toString()
    • toDate

      public PlainDate toDate()

      Synonym for getCalendarDate().

      Returns:
      calendar date component
      Since:
      3.6/4.4
      See Also:
      getCalendarDate()
    • toTime

      public PlainTime toTime()

      Synonym for getWallTime().

      Returns:
      wall time component
      Since:
      3.6/4.4
      See Also:
      getWallTime()
    • print

      public String print(TemporalFormatter<PlainTimestamp> printer)

      Creates a formatted output of this instance.

      Parameters:
      printer - helps to format this instance
      Returns:
      formatted string
      Since:
      5.0
    • parse

      public static PlainTimestamp parse(String text, TemporalFormatter<PlainTimestamp> parser)

      Parses given text to an instance of this class.

      Parameters:
      text - text to be parsed
      parser - helps to parse given text
      Returns:
      parsed result
      Throws:
      IndexOutOfBoundsException - if the text is empty
      ChronoException - if the text is not parseable
      Since:
      5.0
    • toTemporalAccessor

      public LocalDateTime toTemporalAccessor()
      Description copied from interface: ThreetenAdapter

      Converts this object to a TemporalAccessor.

      Any implementation is required to return a new object with a different concrete type, not this instance.

      Specified by:
      toTemporalAccessor in interface ThreetenAdapter
      Returns:
      converted Threeten-object (always as new object)
    • axis

      public static TimeAxis<IsoUnit,​PlainTimestamp> axis()

      Provides a static access to the associated time axis respective chronology which contains the chronological rules.

      Returns:
      chronological system as time axis (never null)
    • threeten

      public static Chronology<LocalDateTime> threeten()

      Obtains a bridge chronology for the type java.time.LocalDateTime.

      Returns:
      rule engine adapted for the type java.time.LocalDateTime
      Since:
      5.0
      See Also:
      axis()
    • atUTC

      public Moment atUTC()

      Combines this local timestamp with the timezone offset UTC+00:00 to a global UTC-moment.

      Returns:
      global UTC-moment based on this local timestamp interpreted at offset UTC+00:00
      See Also:
      at(ZonalOffset)
    • at

      public Moment at(ZonalOffset offset)

      Combines this local timestamp with the given timezone offset to a global UTC-moment.

      Parameters:
      offset - timezone offset
      Returns:
      global UTC-moment based on this local timestamp interpreted at given offset
      Since:
      1.2
      See Also:
      atUTC(), in(Timezone)
    • inStdTimezone

      public Moment inStdTimezone()

      Combines this local timestamp with the system timezone to a global UTC-moment.

      Returns:
      global UTC-moment based on this local timestamp interpreted in system timezone
      Since:
      1.2
      See Also:
      Timezone.ofSystem(), inTimezone(TZID)
    • inTimezone

      public Moment inTimezone(TZID tzid)

      Combines this local timestamp with given timezone to a global UTC-moment.

      Parameters:
      tzid - timezone id
      Returns:
      global UTC-moment based on this local timestamp interpreted in given timezone
      Throws:
      IllegalArgumentException - if given timezone cannot be loaded
      Since:
      1.2
      See Also:
      Timezone.of(TZID), inStdTimezone()
    • in

      public Moment in(Timezone tz)

      Combines this local timestamp with given timezone to a global UTC-moment.

      Parameters:
      tz - timezone
      Returns:
      global UTC-moment based on this local timestamp interpreted in given timezone
      Since:
      1.2
      See Also:
      Timezone.of(String)
    • inLocalView

      public ZonalDateTime inLocalView()
      Returns:
      ZonalDateTime
      Since:
      3.16/4.13
    • inZonalView

      public ZonalDateTime inZonalView(Timezone tz)

      Converts this instance to a combination of UTC-moment, given timezone and its zonal timestamp.

      Attention: Due to winter/summer-time-changes the resulting zonal timestamp (ZonalDateTime.toTimestamp()) can deviate from this plain timestamp.

      Parameters:
      tz - timezone
      Returns:
      ZonalDateTime
      Since:
      3.16/4.13
    • isValid

      public boolean isValid(TZID tzid)

      Does this local timestamp exist in given timezone?

      Parameters:
      tzid - timezone id (optional)
      Returns:
      true if this timestamp is valid in given timezone
      Throws:
      IllegalArgumentException - if given timezone cannot be loaded
    • normalize

      public Duration<IsoUnit> normalize(TimeSpan<? extends IsoUnit> timespan)

      Normalizes given timespan using years, months, days and all clock units.

      This normalizer can also convert from days to months. Example:

        Duration<CalendarUnit> dur = Duration.of(30, CalendarUnit.DAYS);
        Duration<IsoUnit> result =
            PlainTimestamp.of(2012, 2, 28, 0, 0).normalize(dur);
        System.out.println(result); // output: P1M1D (leap year!)
       
      Specified by:
      normalize in interface Normalizer<IsoUnit>
      Parameters:
      timespan - to be normalized
      Returns:
      normalized duration
      Since:
      2.0
      See Also:
      Duration.with(Normalizer)
    • plus

      public PlainTimestamp plus(long amount, CalendarUnit unit)

      Adds given amount in units to this timestamp and yields the result of addition.

      Covers the most important calendar units and is overloaded for performance reasons.

      Parameters:
      amount - the amount of units to be added to this timestamp (maybe negative)
      unit - the unit to be used in addition
      Returns:
      result of addition as changed copy while this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      4.19
      See Also:
      plus(long, IsoUnit)
    • plus

      public PlainTimestamp plus(long amount, ClockUnit unit)

      Adds given amount in units to this timestamp and yields the result of addition.

      Covers the most important clock units and is overloaded for performance reasons.

      Parameters:
      amount - the amount of units to be added to this timestamp (maybe negative)
      unit - the unit to be used in addition
      Returns:
      result of addition as changed copy while this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      4.19
      See Also:
      plus(long, IsoUnit)
    • minus

      public PlainTimestamp minus(long amount, CalendarUnit unit)

      Subtracts given amount in units from this timestamp and yields the result of subtraction.

      Covers the most important calendar units and is overloaded for performance reasons.

      Parameters:
      amount - the amount of units to be subtracted from this timestamp (maybe negative)
      unit - the unit to be used in subtraction
      Returns:
      result of subtraction as changed copy while this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      4.19
      See Also:
      minus(long, IsoUnit)
    • minus

      public PlainTimestamp minus(long amount, ClockUnit unit)

      Subtracts given amount in units from this timestamp and yields the result of subtraction.

      Covers the most important clock units and is overloaded for performance reasons.

      Parameters:
      amount - the amount of units to be subtracted from this timestamp (maybe negative)
      unit - the unit to be used in subtraction
      Returns:
      result of subtraction as changed copy while this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      4.19
      See Also:
      minus(long, IsoUnit)