# Class HealthTimeRange

java.lang.Object
com.codename1.health.HealthTimeRange

public final class HealthTimeRange extends Object

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 Type
  Method
  Description
  `static HealthTimeRange`
  `at(long instantMillis)`
  A zero-width range at one instant, for querying a single moment.
  `static HealthTimeRange`
  `between(long startMillis, long endMillis)`
  An explicit span.
  `static HealthTimeRange`
  `calendarDays(int count, TimeZone tz)`
  The last `count` calendar days in `tz`, from local midnight at the start of the first day through now.
  `boolean`
  `contains(long millis)`
  `true` when `millis` falls in `[start, end)`.
  `long`
  `getDurationMillis()`
  The span in milliseconds, or `Long.MAX_VALUE` when open-ended.
  `long`
  `getEndMillis()`
  Exclusive end, epoch millis UTC.
  `long`
  `getStartMillis()`
  Inclusive start, epoch millis UTC.
  `boolean`
  `isOpenEnded()`
  `true` when this range was built by `since(long)` and its end is resolved at query time rather than fixed.
  `static HealthTimeRange`
  `lastDays(int days)`
  The last `days` times 24 hours, ending now.
  `static HealthTimeRange`
  `lastHours(int hours)`
  The last `hours` hours, ending now.
  `static HealthTimeRange`
  `lastMillis(long durationMillis)`
  The last `durationMillis` milliseconds, ending now.
  `HealthTimeRange`
  `resolve(long nowMillis)`
  This range with its open end resolved to `nowMillis`.
  `static HealthTimeRange`
  `since(long startMillis)`
  Everything from `startMillis` onwards.
  `static HealthTimeRange`
  `today(TimeZone tz)`
  Today, from local midnight to now, in `tz`.
  `String`
  `toString()`
  Returns a string representation of the object.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## 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 zero-width range at one instant, for querying a single moment.

  - ### 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,TimeZone)`.

  - ### today

    public static HealthTimeRange today(TimeZone tz)
    Today, from local midnight to now, in `tz`.

  - ### calendarDays

    public static HealthTimeRange calendarDays(int count, TimeZone tz)
    The last `count` calendar days in `tz`, 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.

  - ### 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()
    Description copied from class: `Object`
    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())
    Overrides:
      `toString` in class `Object`