Class HealthTimeRange
A half-open span of time, [start, end), in epoch milliseconds UTC.
Why epoch millis rather than java.time
java.time is available in Codename One, and the calendar API uses it.
Health does not, for three reasons: a month of continuous heart rate is
tens of thousands of points and one Instant per point is real memory
pressure on a phone; com.codename1.location and
com.codename1.bluetooth already speak long millis and health data
flows between all three; and both platform SDKs are millisecond-based
at the boundary anyway.
Where calendar semantics genuinely matter -- "the last seven days" is
not "the last 604800000 milliseconds" across a daylight-saving
transition -- the factory takes an explicit TimeZone. Nothing in this
API silently reads the JVM default.
-
Method Summary
Modifier and TypeMethodDescriptionstatic HealthTimeRangeat(long instantMillis) A range covering exactly one instant.static HealthTimeRangeThe instantat, with no duration.static HealthTimeRangebetween(long startMillis, long endMillis) An explicit span.static HealthTimeRangeThe window between two instants.static HealthTimeRangecalendarDays(int count, ZoneId zone) The lastcountcalendar days inzone, from local midnight at the start of the first day through now.booleancontains(long millis) truewhenmillisfalls in[start, end).How long this range covers, or null while it is open-ended.longThe span in milliseconds, orLong.MAX_VALUEwhen open-ended.getEnd()The end of this range, or null while it is still open-ended -- there is no instant to name untilresolve(long)picks one.longExclusive end, epoch millis UTC.getStart()The start of this range.longInclusive start, epoch millis UTC.booleantruewhen this range was built bysince(long)and its end is resolved at query time rather than fixed.static HealthTimeRangeThe lastwindow, ending now.static HealthTimeRangelastDays(int days) The lastdaystimes 24 hours, ending now.static HealthTimeRangelastHours(int hours) The lasthourshours, ending now.static HealthTimeRangelastMillis(long durationMillis) The lastdurationMillismilliseconds, ending now.resolve(long nowMillis) This range with its open end resolved tonowMillis.static HealthTimeRangesince(long startMillis) Everything fromstartMillisonwards.static HealthTimeRangeEverything fromstartonwards.static HealthTimeRangeToday, from local midnight to now, inzone.toString()Returns a string representation of the object.
-
Method Details
-
between
An explicit span.endis exclusive: a sample stamped exactly atendbelongs to the next range, which is what makes adjacent buckets tile without double-counting. -
at
A range covering exactly one instant.
One millisecond wide rather than zero: ranges are half-open, so
[t,t)contains nothing at all and the factory documented for querying a single moment returned an empty result for every input, including a sample stamped exactly att. -
lastMillis
The lastdurationMillismilliseconds, ending now. -
lastHours
The lasthourshours, ending now. -
lastDays
The lastdaystimes 24 hours, ending now. This is a rolling window, not a calendar span -- for "the last seven calendar days" usecalendarDays(int,ZoneId). -
today
Today, from local midnight to now, inzone. -
calendarDays
The lastcountcalendar days inzone, from local midnight at the start of the first day through now. Correct across daylight-saving transitions, where a day is 23 or 25 hours. -
since
Everything fromstartMillisonwards. The end is resolved to the wall clock at the moment the query executes. -
since
Everything fromstartonwards. -
between
The window between two instants. -
at
The instantat, with no duration. -
last
The lastwindow, ending now. -
getStart
The start of this range. -
getEnd
The end of this range, or null while it is still open-ended -- there is no instant to name untilresolve(long)picks one. -
getDuration
How long this range covers, or null while it is open-ended. -
getStartMillis
public long getStartMillis()Inclusive start, epoch millis UTC. -
getEndMillis
public long getEndMillis()Exclusive end, epoch millis UTC.Long.MAX_VALUEwhenisOpenEnded(). -
isOpenEnded
public boolean isOpenEnded()truewhen this range was built bysince(long)and its end is resolved at query time rather than fixed. -
getDurationMillis
public long getDurationMillis()The span in milliseconds, orLong.MAX_VALUEwhen open-ended. -
contains
public boolean contains(long millis) truewhenmillisfalls in[start, end). A zero-width range contains nothing. -
resolve
This range with its open end resolved tonowMillis. Returnsthiswhen the range is already closed. -
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
-