public final class HealthTimeRange

  1. Object
  2. 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

public static HealthTimeRange between(long startMillis, long endMillis)An explicit span.
public static HealthTimeRange at(long instantMillis)A range covering exactly one instant.
public static HealthTimeRange lastMillis(long durationMillis)The last durationMillis milliseconds, ending now.
public static HealthTimeRange lastHours(int hours)The last hours hours, ending now.
public static HealthTimeRange lastDays(int days)The last days times 24 hours, ending now.
public static HealthTimeRange today(ZoneId zone)Today, from local midnight to now, in zone.
public static HealthTimeRange calendarDays(int count, ZoneId zone)The last count calendar days in zone, from local midnight at the start of the first day through now.
public static HealthTimeRange since(long startMillis)Everything from startMillis onwards.
public static HealthTimeRange since(Instant start)Everything from start onwards.
public static HealthTimeRange between(Instant start, Instant end)The window between two instants.
public static HealthTimeRange at(Instant at)The instant at, with no duration.
public static HealthTimeRange last(Duration window)The last window, ending now.
public Instant getStart()The start of this range.
public Instant getEnd()The end of this range, or null while it is still open-ended – there is no instant to name until resolve(long) picks one.
public Duration getDuration()How long this range covers, or null while it is open-ended.
public long getStartMillis()Inclusive start, epoch millis UTC.
public long getEndMillis()Exclusive end, epoch millis UTC.
public boolean isOpenEnded()true when this range was built by since(long) and its end is resolved at query time rather than fixed.
public long getDurationMillis()The span in milliseconds, or Long.MAX_VALUE when open-ended.
public boolean contains(long millis)true when millis falls in [start, end).
public HealthTimeRange resolve(long nowMillis)This range with its open end resolved to nowMillis.
public String toString()Returns a string representation of the object.

Inherited methods

Method details

between

public static HealthTimeRange between(long startMillis, long endMillis)
An explicit span. 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)
The last durationMillis milliseconds, ending now.

lastHours

public static HealthTimeRange lastHours(int hours)
The last hours hours, ending now.

lastDays

public static HealthTimeRange lastDays(int days)
The last 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)
Today, from local midnight to now, in zone.

calendarDays

public static HealthTimeRange calendarDays(int count, ZoneId zone)
The last 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)
Everything from startMillis onwards. The end is resolved to the wall clock at the moment the query executes.

since

public static HealthTimeRange since(Instant start)
Everything from start onwards.

between

public static HealthTimeRange between(Instant start, Instant end)
The window between two instants.

at

public static HealthTimeRange at(Instant at)
The instant at, with no duration.

last

public static HealthTimeRange last(Duration window)
The last window, ending now.

getStart

public Instant getStart()
The start of this range.

getEnd

public Instant getEnd()
The end of this range, or null while it is still open-ended – there is no instant to name until resolve(long) picks one.

getDuration

public Duration 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_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()
The span in milliseconds, or 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)
This range with its open end resolved to nowMillis. Returns this when the range is already closed.

toString

public String toString()
Returns 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())