Class HealthTimeRange
java.lang.Object
com.codename1.health.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 zero-width range at one instant, for querying a single moment.static HealthTimeRangebetween(long startMillis, long endMillis) An explicit span.static HealthTimeRangecalendarDays(int count, TimeZone tz) The lastcountcalendar days intz, from local midnight at the start of the first day through now.booleancontains(long millis) truewhenmillisfalls in[start, end).longThe span in milliseconds, orLong.MAX_VALUEwhen open-ended.longExclusive end, epoch millis UTC.longInclusive start, epoch millis UTC.booleantruewhen this range was built bysince(long)and its end is resolved at query time rather than fixed.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 HealthTimeRangeToday, from local midnight to now, intz.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 zero-width range at one instant, for querying a single moment. -
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,TimeZone). -
today
Today, from local midnight to now, intz. -
calendarDays
The lastcountcalendar days intz, 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. -
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())
-