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.network
: Network code ("NEM"
|"WEM"
|"AU"
)
- Number representing timezone offset in hours (e.g., 10 for AEST/UTC+10)
getNetworkTimezoneOffset
Get timezone offset in milliseconds for a network.network
: Network code ("NEM"
|"WEM"
|"AU"
)
- Number representing timezone offset in milliseconds
Date Handling Functions
isAware
Check if a date string contains timezone information.dateStr
: Date string or Date object to check
- Boolean indicating if the date string contains timezone information
makeAware
Make a date timezone aware by adding the network’s timezone offset.date
: Date string or Date object to make timezone awarenetwork
: Network code to get timezone from
- ISO string with timezone information
stripTimezone
Remove timezone information from a date string.dateStr
: Date string to strip timezone from
- Date string without timezone information
Interval Functions
getLastCompleteInterval
Get the last complete 5-minute interval for a network.network
: Network code to get timezone from
- ISO string of the last complete 5-minute interval in network time (without timezone information)
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: