Utility Functions
Helper functions and utilities for working with the OpenElectricity client
Utility Functions
The OpenElectricity client provides several utility functions to help you work with dates, timezones, and other common operations. These utilities are designed to handle the complexities of working with different electricity networks and their specific timezone requirements.
Date and Time Utilities
Network Timezones
The client handles data from different electricity networks in Australia, each with their own timezone:
- NEM (National Electricity Market): AEST/UTC+10
- WEM (Western Australia): AWST/UTC+8
- AU (Australia): AEST/UTC+10 (default)
Timezone Functions
getNetworkTimezone
Get the timezone offset in hours for a specific network.
Parameters:
network
: Network code ("NEM"
|"WEM"
|"AU"
)
Returns:
- Number representing timezone offset in hours (e.g., 10 for AEST/UTC+10)
Example:
getNetworkTimezoneOffset
Get timezone offset in milliseconds for a network.
Parameters:
network
: Network code ("NEM"
|"WEM"
|"AU"
)
Returns:
- Number representing timezone offset in milliseconds
Example:
Date Handling Functions
isAware
Check if a date string contains timezone information.
Parameters:
dateStr
: Date string or Date object to check
Returns:
- Boolean indicating if the date string contains timezone information
Example:
makeAware
Make a date timezone aware by adding the network’s timezone offset.
Parameters:
date
: Date string or Date object to make timezone awarenetwork
: Network code to get timezone from
Returns:
- ISO string with timezone information
Example:
stripTimezone
Remove timezone information from a date string.
Parameters:
dateStr
: Date string to strip timezone from
Returns:
- Date string without timezone information
Example:
Interval Functions
getLastCompleteInterval
Get the last complete 5-minute interval for a network.
Parameters:
network
: Network code to get timezone from
Returns:
- ISO string of the last complete 5-minute interval in network time (without timezone information)
Example:
Best Practices
Working with Timezones
-
Network-Specific Times: Always use the appropriate network timezone when working with dates:
-
API Submissions: The API expects timezone-naive dates in network time:
-
Interval Data: Use
getLastCompleteInterval
for real-time data:
Date Validation
-
Check Timezone Information:
-
Network-Specific Processing: