# sp2ts
A Python module for converting between the settlement periods used by GB electricity industry and Unix timestamps.
**Latest Version: 1.0.0**
## About this repository
* Convert settlement date and settlement period to Unix timestamp and vice versa.
* Convert settlement date and settlement period to Python datetime object and vice versa.
* Convert Python datetime objects to Unix timestamp and vice versa.
* Developed and tested with Python 3.11, should work for 3.9+.
## How do I get set up?
Run `pip install sp2ts`
(or make sure you have Git installed - [Download Git](https://git-scm.com/downloads) - 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
```
## Usage
The module contains the following functions:
* `to_unixtime(datetime, timezone=None)`
- Convert a Python datetime object to Unix timestamp. The datetime object must be timezone aware or else you must pass the timezone as an Olsen timezone string.
* `from_unixtime(timestamp, timezone="UTC")`
- Convert a Unix timestamp to a (timezone-aware) Python datetime object
* `sp2ts(date, sp, closed="right")`
- Convert a date and settlement period into a Unix timestamp. The `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")`
- Convert a date and settlement period into a (timezone-aware) Python datetime object. The `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)`
- Convert a Unix timestamp into a date and settlement period. Settlement periods are considered to be "closed right" i.e. SP 1 refers to the interval 00:00:00 < t <= 00:30:00.
* `dt2sp(datetime, timezone=None)`
- Convert a Python datetime object into a date and settlement period. The `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.
### Example
```
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
## How do I update?
Run `pip install --upgrade sp2ts`.
## How do I run tests?
Clone the repo locally, then run the following command from the repo's root:
```>> python -m Tests.test_sp2ts```
## Who do I talk to?
* Jamie Taylor - [jamie.taylor@sheffield.ac.uk](mailto:jamie.taylor@sheffield.ac.uk "Email Jamie") - [SheffieldSolar](https://github.com/SheffieldSolar)
## Authors
* **Jamie Taylor** - [SheffieldSolar](https://github.com/SheffieldSolar)
Raw data
{
"_id": null,
"home_page": "",
"name": "sp2ts",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "Jamie Taylor <jamie.taylor@sheffield.ac.uk>",
"keywords": "timestamp,timezone,settlement period,settlement date,settlement time,electricity market",
"author": "",
"author_email": "Jamie Taylor <jamie.taylor@sheffield.ac.uk>",
"download_url": "https://files.pythonhosted.org/packages/5a/3b/c2ac22b93a7d8b186439743cc912686116b6a6de82752d96e8e528932a50/sp2ts-1.0.0.tar.gz",
"platform": null,
"description": "\r\n# sp2ts\r\nA Python module for converting between the settlement periods used by GB electricity industry and Unix timestamps.\r\n\r\n**Latest Version: 1.0.0**\r\n\r\n## About this repository\r\n\r\n* Convert settlement date and settlement period to Unix timestamp and vice versa.\r\n* Convert settlement date and settlement period to Python datetime object and vice versa.\r\n* Convert Python datetime objects to Unix timestamp and vice versa.\r\n* Developed and tested with Python 3.11, should work for 3.9+.\r\n\r\n## How do I get set up?\r\n\r\nRun `pip install sp2ts`\r\n\r\n(or make sure you have Git installed - [Download Git](https://git-scm.com/downloads) - then run `pip install git+https://github.com/SheffieldSolar/sp2ts/`)\r\n\r\nCheck that the installation was successful by running the following command from terminal / command-line:\r\n\r\n```>> sp2ts -h```\r\n\r\nThis will print the helper for the command line interface which can be useful for working interactively:\r\n\r\n```\r\nusage: sp2ts.py [-h] [-d <yyyy-mm-dd>] [-sp <[1..50]>]\r\n [-ts <seconds since epoch>] [-dt <yyyy-mm-ddTHH:MM:SS>]\r\n [-tz <Olson timezone string>]\r\n\r\nThis is a command line interface (CLI) for the sp2ts module.\r\n\r\noptional arguments:\r\n -h, --help show this help message and exit\r\n -d <yyyy-mm-dd>, --date <yyyy-mm-dd>\r\n Specify a date (use only in conjuction with\r\n -sp/--settlement-period).\r\n -sp <[1..50]>, --settlement-period <[1..50]>\r\n Specify a settlement period (use only in conjuction\r\n with -d/--date).\r\n -ts <seconds since epoch>, --timestamp <seconds since epoch>\r\n Specify a timestamp (all other options will be\r\n ignored).\r\n -dt <yyyy-mm-ddTHH:MM:SS>, --datetime <yyyy-mm-ddTHH:MM:SS>\r\n Specify a datetime (optionally also specify\r\n -tz/--timezone).\r\n -tz <Olson timezone string>, --timezone <Olson timezone string>\r\n Specify a timezone (used only in conjunction with\r\n -dt/--datetime, default is 'UTC').\r\n\r\nJamie Taylor, 2020-03-31\r\n```\r\n\r\n## Usage\r\n\r\nThe module contains the following functions:\r\n\r\n* `to_unixtime(datetime, timezone=None)`\r\n - Convert a Python datetime object to Unix timestamp. The datetime object must be timezone aware or else you must pass the timezone as an Olsen timezone string.\r\n* `from_unixtime(timestamp, timezone=\"UTC\")`\r\n - Convert a Unix timestamp to a (timezone-aware) Python datetime object\r\n* `sp2ts(date, sp, closed=\"right\")`\r\n - Convert a date and settlement period into a Unix timestamp. The `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.\r\n* `sp2dt(date, sp, closed=\"right\")`\r\n - Convert a date and settlement period into a (timezone-aware) Python datetime object. The `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.\r\n* `ts2sp(timestamp)`\r\n - Convert a Unix timestamp into a date and settlement period. Settlement periods are considered to be \"closed right\" i.e. SP 1 refers to the interval 00:00:00 < t <= 00:30:00.\r\n* `dt2sp(datetime, timezone=None)`\r\n - Convert a Python datetime object into a date and settlement period. The `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.\r\n\r\n### Example\r\n```\r\nfrom datetime import date\r\n\r\nfrom sp2ts import sp2ts, ts2sp, from_unixtime\r\n\r\ndef main():\r\n # Converting date and SP to timestamp...\r\n mydate = date(2020, 3, 28)\r\n mysp = 24\r\n mytimestamp = sp2ts(mydate, mysp)\r\n print(f\"{mydate} SP{mysp} --> {mytimestamp} ({from_unixtime(mytimestamp)})\")\r\n # Converting timestamp to date and SP...\r\n mytimestamp = 1585396800 # SP ending 2020-03-28T12:00:00Z\r\n mydate, mysp = ts2sp(mytimestamp)\r\n print(f\"{mytimestamp} ({from_unixtime(mytimestamp)}) --> {mydate} SP{mysp}\")\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n```\r\n\r\n> 2020-03-28 SP24 --> 1585396800 (2020-03-28 12:00:00+00:00)\r\n\r\n> 1585396800 (2020-03-28 12:00:00+00:00) --> 2020-03-28 SP24\r\n\r\n## How do I update?\r\n\r\nRun `pip install --upgrade sp2ts`.\r\n\r\n## How do I run tests?\r\n\r\nClone the repo locally, then run the following command from the repo's root:\r\n\r\n```>> python -m Tests.test_sp2ts```\r\n\r\n## Who do I talk to?\r\n\r\n* Jamie Taylor - [jamie.taylor@sheffield.ac.uk](mailto:jamie.taylor@sheffield.ac.uk \"Email Jamie\") - [SheffieldSolar](https://github.com/SheffieldSolar)\r\n\r\n## Authors\r\n\r\n* **Jamie Taylor** - [SheffieldSolar](https://github.com/SheffieldSolar)\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Convert between the settlement periods used by GB electricity industry and Unix timestamps.",
"version": "1.0.0",
"project_urls": {
"Bug Tracker": "https://github.com/SheffieldSolar/sp2ts/issues",
"Documentation": "https://sheffieldsolar.github.io/PV_Live-API/build/html/index.html",
"Homepage": "https://github.com/SheffieldSolar/sp2ts",
"Repository": "https://github.com/SheffieldSolar/sp2ts"
},
"split_keywords": [
"timestamp",
"timezone",
"settlement period",
"settlement date",
"settlement time",
"electricity market"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a5846ccc6050a92c2e76f1c48224a40d6655e93d4be5e789707348196a11111f",
"md5": "f7b57de1a1e09196de610f42f49c58b5",
"sha256": "10798f125fd079c46dc5842fe1ca4aa6f18a6479f1c6ccf071249712454d3ed6"
},
"downloads": -1,
"filename": "sp2ts-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f7b57de1a1e09196de610f42f49c58b5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 23633,
"upload_time": "2024-02-20T22:21:25",
"upload_time_iso_8601": "2024-02-20T22:21:25.176667Z",
"url": "https://files.pythonhosted.org/packages/a5/84/6ccc6050a92c2e76f1c48224a40d6655e93d4be5e789707348196a11111f/sp2ts-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5a3bc2ac22b93a7d8b186439743cc912686116b6a6de82752d96e8e528932a50",
"md5": "23b2871d342acf3541bab1f58261e9ab",
"sha256": "7d60b908d67f1fa3fd518688be778cfaaa659c704ddffc4e37dfaf2d94187f94"
},
"downloads": -1,
"filename": "sp2ts-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "23b2871d342acf3541bab1f58261e9ab",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 24566,
"upload_time": "2024-02-20T22:21:28",
"upload_time_iso_8601": "2024-02-20T22:21:28.722863Z",
"url": "https://files.pythonhosted.org/packages/5a/3b/c2ac22b93a7d8b186439743cc912686116b6a6de82752d96e8e528932a50/sp2ts-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-20 22:21:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SheffieldSolar",
"github_project": "sp2ts",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "sp2ts"
}