
[](https://github.com/subretu/unic/actions/workflows/pytest.yml)
[](https://github.com/subretu/unic/actions/workflows/format_check.yml)
[](https://github.com/subretu/unic/actions/workflows/lint_check.yml)
# unic
`unic` is a python package that can convert various units.
## Conversion Targets
- The current available conversion targets are as follows.
<details>
<summary>Time Unit</summary>
- TimeModel
- minute / second / milisecond → hour
- hour / second / milisecond → minute
- hour / minute / milisecond → second
- hour / minute / second → milisecond
- DatetimeModel
- unixtime / unixtime+timezone → datetime.datetime
- unixtime / unixtime+timezone → datetime.date
- UnixtimeModel
- string(yyyy-mm-dd hh:mm:ss) / string(yyyy-mm-dd hh:mm:ss)+timezone → unixtime(default is seconds)
- string(yyyy/mm/dd hh:mm:ss) / string(yyyy/mm/dd hh:mm:ss)+timezone → unixtime(default is seconds)
</details>
<details>
<summary>Length Unit</summary>
- MetricSystemModel
- Target Metric System Units
```
nm, um, mm, cm, m, km, Mm, Gm, Tm
```
※ um : represents ㎛.
- The target metric system units are can be converted to each other.
</details>
## Installing
```
pip install unic
```
## How to
- See the [UserGuide](docs/UserGuide.md).
## Example
### Time Unit
#### TimeModel
```python
import unic
convert_model = unic.load_model("time")
# Convert hour to minute
convert_min = convert_model.convert(2, from_unit="hour", to_unit="min")
# Convert hour to minute (batch processing)
convert_min = convert_model.convert_batch([2,4,6], from_unit="hour", to_unit="min")
```
#### DatetimeModel
```python
import unic
convert_model = unic.load_model("datetime")
# Convert to datatime
convert_datetime = convert_model.convert(1577841753, format="datetime")
# Convert to datatime (batch processing)
convert_datetime = convert_model.convert_batch([1577841753,1577941753], format="datetime")
# Convert to date
convert_datetime = convert_model.convert(1577841753, format="date")
```
#### UnixtimeModel
```python
import unic
convert_model = unic.load_model("unixtime")
# Specify time zone
convert_unixtime = convert_model.convert("2023-05-12 10:15:20", tz="Asia/Tokyo")
# Specify unit(if not specified, the unit defaults to seconds)
convert_unixtime = convert_model.convert("2023-05-12 10:15:20.123", tz="Asia/Tokyo", unit="msec")
# Specify time zone (batch processing)
convert_unixtime = convert_model.convert_batch(["2023-05-12 10:15:20","2023-05-13 10:15:20","2023-05-14 10:15:20"], tz="Asia/Tokyo")
```
### Length Unit
#### MetricSystemModel
```python
import unic
convert_model = unic.load_model("metric_system")
# Convert cm to m
convert_m = convert_model.convert(20, from_unit="cm", to_unit="m")
# Convert cm to m (batch processing)
convert_m = convert_model.convert_batch([20,50,100,200], from_unit="cm", to_unit="m")
```
Raw data
{
"_id": null,
"home_page": "https://github.com/subretu/unic",
"name": "unic",
"maintainer": "Subretu",
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "unit, convert, time, timestamp, length",
"author": "Subretu",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/29/0c/f5a8cce1c227a00031bb7da7da9cc7185dacb9c128f522065bc8c37eb6f5/unic-2.0.0.tar.gz",
"platform": null,
"description": "\n[](https://github.com/subretu/unic/actions/workflows/pytest.yml)\n[](https://github.com/subretu/unic/actions/workflows/format_check.yml)\n[](https://github.com/subretu/unic/actions/workflows/lint_check.yml)\n\n# unic\n `unic` is a python package that can convert various units.\n\n## Conversion Targets\n- The current available conversion targets are as follows.\n\n <details>\n <summary>Time Unit</summary>\n\n - TimeModel\n - minute / second / milisecond \u2192 hour\n - hour / second / milisecond \u2192 minute\n - hour / minute / milisecond \u2192 second\n - hour / minute / second \u2192 milisecond\n - DatetimeModel\n - unixtime / unixtime+timezone \u2192 datetime.datetime\n - unixtime / unixtime+timezone \u2192 datetime.date\n - UnixtimeModel\n - string(yyyy-mm-dd hh:mm:ss) / string(yyyy-mm-dd hh:mm:ss)+timezone \u2192 unixtime(default is seconds)\n - string(yyyy/mm/dd hh:mm:ss) / string(yyyy/mm/dd hh:mm:ss)+timezone \u2192 unixtime(default is seconds)\n </details>\n\n <details>\n <summary>Length Unit</summary>\n\n - MetricSystemModel\n - Target Metric System Units\n\n ```\n nm, um, mm, cm, m, km, Mm, Gm, Tm\n ```\n \u203b um : represents \u339b.\n - The target metric system units are can be converted to each other.\n\n </details>\n\n## Installing\n\n ```\n pip install unic\n ```\n\n## How to\n- See the [UserGuide](docs/UserGuide.md).\n\n## Example\n### Time Unit\n#### TimeModel\n\n```python\nimport unic\n\n\nconvert_model = unic.load_model(\"time\")\n# Convert hour to minute\nconvert_min = convert_model.convert(2, from_unit=\"hour\", to_unit=\"min\")\n# Convert hour to minute (batch processing)\nconvert_min = convert_model.convert_batch([2,4,6], from_unit=\"hour\", to_unit=\"min\")\n```\n\n#### DatetimeModel\n\n```python\nimport unic\n\n\nconvert_model = unic.load_model(\"datetime\")\n# Convert to datatime\nconvert_datetime = convert_model.convert(1577841753, format=\"datetime\")\n# Convert to datatime (batch processing)\nconvert_datetime = convert_model.convert_batch([1577841753,1577941753], format=\"datetime\")\n\n# Convert to date\nconvert_datetime = convert_model.convert(1577841753, format=\"date\")\n```\n\n#### UnixtimeModel\n\n```python\nimport unic\n\n\nconvert_model = unic.load_model(\"unixtime\")\n# Specify time zone\nconvert_unixtime = convert_model.convert(\"2023-05-12 10:15:20\", tz=\"Asia/Tokyo\")\n# Specify unit(if not specified, the unit defaults to seconds)\nconvert_unixtime = convert_model.convert(\"2023-05-12 10:15:20.123\", tz=\"Asia/Tokyo\", unit=\"msec\")\n# Specify time zone (batch processing)\nconvert_unixtime = convert_model.convert_batch([\"2023-05-12 10:15:20\",\"2023-05-13 10:15:20\",\"2023-05-14 10:15:20\"], tz=\"Asia/Tokyo\")\n```\n\n### Length Unit\n#### MetricSystemModel\n\n```python\nimport unic\n\n\nconvert_model = unic.load_model(\"metric_system\")\n# Convert cm to m\nconvert_m = convert_model.convert(20, from_unit=\"cm\", to_unit=\"m\")\n# Convert cm to m (batch processing)\nconvert_m = convert_model.convert_batch([20,50,100,200], from_unit=\"cm\", to_unit=\"m\")\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python package for converting various units.",
"version": "2.0.0",
"project_urls": {
"Homepage": "https://github.com/subretu/unic",
"Repository": "https://github.com/subretu/unic"
},
"split_keywords": [
"unit",
" convert",
" time",
" timestamp",
" length"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e91842d8a7e54941b2e3753ce00d756d6ac54fbb1965c375db93388c88774782",
"md5": "c947d936a5700f6f1e0a182ba330eaf5",
"sha256": "761519299abe1e00a4ec54b5b52db00a8d4e5e79839952a587e99b683a444c24"
},
"downloads": -1,
"filename": "unic-2.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c947d936a5700f6f1e0a182ba330eaf5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 13426,
"upload_time": "2025-02-08T13:32:18",
"upload_time_iso_8601": "2025-02-08T13:32:18.700290Z",
"url": "https://files.pythonhosted.org/packages/e9/18/42d8a7e54941b2e3753ce00d756d6ac54fbb1965c375db93388c88774782/unic-2.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "290cf5a8cce1c227a00031bb7da7da9cc7185dacb9c128f522065bc8c37eb6f5",
"md5": "e8be657a843ce50240a3734a73d4d87c",
"sha256": "b5e656b34c56b859e7d5ecbddba3674f29485b7cf07ba6506a93eb7387e377ba"
},
"downloads": -1,
"filename": "unic-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "e8be657a843ce50240a3734a73d4d87c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 8633,
"upload_time": "2025-02-08T13:32:21",
"upload_time_iso_8601": "2025-02-08T13:32:21.808948Z",
"url": "https://files.pythonhosted.org/packages/29/0c/f5a8cce1c227a00031bb7da7da9cc7185dacb9c128f522065bc8c37eb6f5/unic-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-08 13:32:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "subretu",
"github_project": "unic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "unic"
}