Module: util

Classes

BitmaskEnum
ComparableEnum
Configuration
Enum
MultiMap
PropMap

Methods


<inner> datumDate(d)

Get a date associated with a "datum" style object.

This function will return a Date instance found via a property on d according to these rules:

  1. date - assumed to be a Date object already and returned directly
  2. localDate - a string in yyyy-MM-dd form, optionally with a string localTime property for an associated time in HH:mm form, treated as UTC
  3. created - a string in yyyy-MM-dd HH:mm:ss.SSS'Z' or yyyy-MM-dd'T'HH:mm:ss.SSS'Z' form

These properties are commonly returned in results from the SolarNetwork API, and thus this method is a handy way to get the dates for those objects.

Note that the localDate and localTime values are parsed as UTC. When formatted the date for display they should be formatted in UTC as well to preserve the expected value.

Parameters:
Name Type Description
d Object

the datum object to extract a date from

Returns:

the extracted date, or null if no date could be extracted

Type
Date

<inner> rollingQueryDateRange(aggregate, aggregateTimeCount [, endDate])

Get a query range appropriate for a given aggregate level.

Returns an object with start and end Date properties, using the given endDate parameter as the basis for calculating the start as an offset backwards in time based on the given aggregate level.

When aggregateTimeCount will be treated as a "next higher" aggregate level from aggregate, like this:

  • < Hour: numHours
  • Hour : numDays
  • Day : numMonths
  • Month : numYears

For example, you might like to render a chart using TenMinute aggregate data for the last 24 hours. You'd call this function like this:

const range = rollingQueryDateRange(Aggregates.TenMinute, 24);

// or, passing a DateRangeConfiguration
const range = rollingQueryDateRange(Aggregates.TenMinute, {numHours:24});
Parameters:
Name Type Argument Description
aggregate module:domain~Aggregation

the aggregate level to get a query range for

aggregateTimeCount number | module:util~DateRangeConfiguration

the number of aggregate time units to use

endDate Date <optional>

the ending date; if not provided the current date will be used

Returns:

the calculated date range

Type
module:util~DateRange

Type Definitions


DateRange

An object that defines a date range.

Type:
  • Object
Properties:
Name Type Description
start Date

the starting date

end Date

the ending date

timeUnit module:domain~Aggregation

the time unit used by the date range

timeCount number

the number of time units in the date range

aggregate module:domain~Aggregation

the aggregate to query with


DateRangeConfiguration

An object that defines levels of date range configuration.

Type:
  • Object
Properties:
Name Type Argument Description
numHours number <optional>

the number of hours to use

numDays number <optional>

the number of days to use

numMonths number <optional>

the number of months to use

numYears number <optional>

the number of years to use