
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Convert between the settlement periods used by GB electricity industry and Unix timestamps.
A Python module for converting between the settlement periods used by GB electricity industry and Unix timestamps.
Latest Version: 1.0.0
Run pip install sp2ts
(or make sure you have Git installed - Download Git - then run pip install git+https://github.com/SheffieldSolar/sp2ts/
)
Check that the installation was successful by running the following command from terminal / command-line:
>> sp2ts -h
This will print the helper for the command line interface which can be useful for working interactively:
usage: sp2ts.py [-h] [-d <yyyy-mm-dd>] [-sp <[1..50]>]
[-ts <seconds since epoch>] [-dt <yyyy-mm-ddTHH:MM:SS>]
[-tz <Olson timezone string>]
This is a command line interface (CLI) for the sp2ts module.
optional arguments:
-h, --help show this help message and exit
-d <yyyy-mm-dd>, --date <yyyy-mm-dd>
Specify a date (use only in conjuction with
-sp/--settlement-period).
-sp <[1..50]>, --settlement-period <[1..50]>
Specify a settlement period (use only in conjuction
with -d/--date).
-ts <seconds since epoch>, --timestamp <seconds since epoch>
Specify a timestamp (all other options will be
ignored).
-dt <yyyy-mm-ddTHH:MM:SS>, --datetime <yyyy-mm-ddTHH:MM:SS>
Specify a datetime (optionally also specify
-tz/--timezone).
-tz <Olson timezone string>, --timezone <Olson timezone string>
Specify a timezone (used only in conjunction with
-dt/--datetime, default is 'UTC').
Jamie Taylor, 2020-03-31
The module contains the following functions:
to_unixtime(datetime, timezone=None)
from_unixtime(timestamp, timezone="UTC")
sp2ts(date, sp, closed="right")
closed
parameter can be "left"
, "middle"
or "right"
(default), which will determine whether the timestamp returned is the start, middle or end of the settlement period respectively.sp2dt(date, sp, closed="right")
closed
parameter can be "left"
, "middle"
or "right"
(default), which will determine whether the timestamp returned is the start, middle or end of the settlement period respectively.ts2sp(timestamp)
dt2sp(datetime, timezone=None)
datetime
must be timezone-aware, or else you must also pass the timezone
as an Olsen timezone string. Settlement periods are considered to be "closed right" i.e. SP 1 refers to the interval 00:00:00 < t <= 00:30:00.from datetime import date
from sp2ts import sp2ts, ts2sp, from_unixtime
def main():
# Converting date and SP to timestamp...
mydate = date(2020, 3, 28)
mysp = 24
mytimestamp = sp2ts(mydate, mysp)
print(f"{mydate} SP{mysp} --> {mytimestamp} ({from_unixtime(mytimestamp)})")
# Converting timestamp to date and SP...
mytimestamp = 1585396800 # SP ending 2020-03-28T12:00:00Z
mydate, mysp = ts2sp(mytimestamp)
print(f"{mytimestamp} ({from_unixtime(mytimestamp)}) --> {mydate} SP{mysp}")
if __name__ == "__main__":
main()
2020-03-28 SP24 --> 1585396800 (2020-03-28 12:00:00+00:00)
1585396800 (2020-03-28 12:00:00+00:00) --> 2020-03-28 SP24
Run pip install --upgrade sp2ts
.
Clone the repo locally, then run the following command from the repo's root:
>> python -m Tests.test_sp2ts
FAQs
Convert between the settlement periods used by GB electricity industry and Unix timestamps.
We found that sp2ts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.