DateTimeWithZone

@CarProtocol
public final class DateTimeWithZone


A time with an associated time zone information.

In order to avoid time zone databases being out of sync between the app and the host, this model avoids using IANA database time zone IDs and instead relies on the app passing the time zone offset and its abbreviated name. Apps can use their time library of choice to retrieve the time zone information.

create and create are provided for convenience if using java.util and java.time respectively. If using another library such as Joda time, create can be used.

Summary

Public methods

static @NonNull DateTimeWithZone
@RequiresApi(value = 26)
create(@NonNull ZonedDateTime zonedDateTime)

Returns an instance of a DateTimeWithZone.

static @NonNull DateTimeWithZone
create(long timeSinceEpochMillis, @NonNull TimeZone timeZone)

Returns an instance of a DateTimeWithZone.

static @NonNull DateTimeWithZone
create(
    long timeSinceEpochMillis,
    @IntRange(from = "-64800", to = 64800) int zoneOffsetSeconds,
    @NonNull String zoneShortName
)

Returns an instance of a DateTimeWithZone.

boolean
long

Returns the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.

int

Returns the offset of the time zone from UTC.

@Nullable String

Returns the abbreviated name of the time zone, for example "PST" for Pacific Standard Time.

int
@NonNull String

Public methods

create

Added in 1.0.0
@RequiresApi(value = 26)
public static @NonNull DateTimeWithZone create(@NonNull ZonedDateTime zonedDateTime)

Returns an instance of a DateTimeWithZone.

Parameters
@NonNull ZonedDateTime zonedDateTime

The time with a time zone. The abbreviated name of this time zone, formatted using the default locale, may be displayed to the user when needed, for example, if this time zone is different than the current system time zone

Throws
java.lang.NullPointerException

if zonedDateTime is null

create

Added in 1.0.0
public static @NonNull DateTimeWithZone create(long timeSinceEpochMillis, @NonNull TimeZone timeZone)

Returns an instance of a DateTimeWithZone.

Parameters
long timeSinceEpochMillis

The number of milliseconds from the epoch of 1970-01-01T00:00:00Z

@NonNull TimeZone timeZone

The time zone at the date specified by timeInUtcMillis. The abbreviated name of this time zone, formatted using the default locale, may be displayed to the user when needed, for example, if this time zone is different than the current system time zone

Throws
java.lang.IllegalArgumentException

if timeSinceEpochMillis is a negative value

java.lang.NullPointerException

if timeZone is null

create

Added in 1.0.0
public static @NonNull DateTimeWithZone create(
    long timeSinceEpochMillis,
    @IntRange(from = "-64800", to = 64800) int zoneOffsetSeconds,
    @NonNull String zoneShortName
)

Returns an instance of a DateTimeWithZone.

Parameters
long timeSinceEpochMillis

The number of milliseconds from the epoch of 1970-01-01T00:00:00Z

@IntRange(from = "-64800", to = 64800) int zoneOffsetSeconds

The offset of the time zone from UTC at the date specified by timeInUtcMillis. This offset must be in the range -18:00 to +18:00, which corresponds to -64800 to +64800

@NonNull String zoneShortName

The abbreviated name of the time zone, for example, "PST" for Pacific Standard Time. This string may be used to display to the user along with the date when needed, for example, if this time zone is different than the current system time zone

Throws
java.lang.IllegalArgumentException

if timeSinceEpochMillis is a negative value, if zoneOffsetSeconds is not within the required range, or if zoneShortName is empty

java.lang.NullPointerException

if zoneShortName is null

equals

Added in 1.4.0-rc02
public boolean equals(@Nullable Object other)

getTimeSinceEpochMillis

Added in 1.0.0
public long getTimeSinceEpochMillis()

Returns the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.

getZoneOffsetSeconds

Added in 1.0.0
public int getZoneOffsetSeconds()

Returns the offset of the time zone from UTC.

getZoneShortName

Added in 1.0.0
public @Nullable String getZoneShortName()

Returns the abbreviated name of the time zone, for example "PST" for Pacific Standard Time.

hashCode

Added in 1.4.0-rc02
public int hashCode()

toString

Added in 1.4.0-rc02
public @NonNull String toString()