Class Hours
java.lang.Object
cloud.opencode.base.date.extra.Hours
- All Implemented Interfaces:
Serializable, Comparable<Hours>, TemporalAmount
Hours unit class representing a number of hours
小时单位类,表示小时数
This class represents a number of hours, similar to Duration but focused on the hours unit. It implements TemporalAmount for use with java.time.
此类表示小时数,类似于Duration但专注于小时单位。实现TemporalAmount以与java.time配合使用。
Features | 主要功能:
- Type-safe hours representation - 类型安全的小时数表示
- Arithmetic operations (plus, minus, multiply, divide) - 算术操作(加、减、乘、除)
- Conversion to Duration, Seconds, Minutes, Days - 转换为Duration、Seconds、Minutes、Days
- TemporalAmount implementation for java.time integration - 实现TemporalAmount以集成java.time
Usage Examples | 使用示例:
Hours h = Hours.of(8);
Hours h2 = Hours.ofDays(2); // 48 hours
Duration d = h.toDuration();
LocalDateTime dt = LocalDateTime.now().plus(h);
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Overflow-safe: Yes (uses Math.addExact/multiplyExact) - 溢出安全: 是(使用Math.addExact/multiplyExact)
- Since:
- JDK 25, opencode-base-date V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionabs()static HoursintdividedBy(long divisor) booleanstatic Hourslongget(TemporalUnit unit) longgetUnits()inthashCode()booleanbooleanbooleanisZero()minus(long hoursToSubtract) multipliedBy(long multiplicand) negated()static Hoursof(long hours) static HoursofDays(long days) static HoursofMinutes(long minutes) plus(long hoursToAdd) subtractFrom(Temporal temporal) toDays()toString()
-
Field Details
-
ZERO
-
-
Method Details
-
of
-
ofMinutes
-
ofDays
-
from
-
between
-
getAmount
public long getAmount() -
isZero
public boolean isZero() -
isNegative
public boolean isNegative() -
isPositive
public boolean isPositive() -
plus
-
plus
-
minus
-
minus
-
multipliedBy
-
dividedBy
-
negated
-
abs
-
toDuration
-
toSeconds
-
toMinutes
-
toDays
-
get
- Specified by:
getin interfaceTemporalAmount
-
getUnits
- Specified by:
getUnitsin interfaceTemporalAmount
-
addTo
- Specified by:
addToin interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFromin interfaceTemporalAmount
-
compareTo
- Specified by:
compareToin interfaceComparable<Hours>
-
equals
-
hashCode
-
toString
-