public final class HealthTimeRange
- Object
- 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.
Methods
Inherited methods
Method details
between
public static HealthTimeRange between(long startMillis, long endMillis)end is exclusive: a sample stamped exactly at
end belongs to the next range, which is what makes adjacent
buckets tile without double-counting.at
public static HealthTimeRange at(long instantMillis)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 at t.
lastMillis
public static HealthTimeRange lastMillis(long durationMillis)durationMillis milliseconds, ending now.lastHours
public static HealthTimeRange lastHours(int hours)hours hours, ending now.lastDays
public static HealthTimeRange lastDays(int days)days times 24 hours, ending now. This is a rolling
window, not a calendar span – for “the last seven calendar
days” use calendarDays(int,ZoneId).today
public static HealthTimeRange today(ZoneId zone)zone.calendarDays
public static HealthTimeRange calendarDays(int count, ZoneId zone)count calendar days in zone, 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
public static HealthTimeRange since(long startMillis)startMillis onwards. The end is resolved to the
wall clock at the moment the query executes.since
public static HealthTimeRange since(Instant start)start onwards.between
public static HealthTimeRange between(Instant start, Instant end)at
public static HealthTimeRange at(Instant at)at, with no duration.last
public static HealthTimeRange last(Duration window)window, ending now.getStart
public Instant getStart()getEnd
public Instant getEnd()resolve(long) picks one.getDuration
public Duration getDuration()getStartMillis
public long getStartMillis()getEndMillis
public long getEndMillis()Long.MAX_VALUE when
isOpenEnded().isOpenEnded
public boolean isOpenEnded()true when this range was built by since(long) and its end is
resolved at query time rather than fixed.getDurationMillis
public long getDurationMillis()Long.MAX_VALUE when open-ended.contains
public boolean contains(long millis)true when millis falls in [start, end). A zero-width range
contains nothing.resolve
public HealthTimeRange resolve(long nowMillis)nowMillis. Returns
this when the range is already closed.toString
public String toString()