Python package for converting various units.
Project description
unic
unic is a python package that can convert various units.
Conversion Targets
-
The current available conversion targets are as follows.
Time Unit
- 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)
Length Unit
- 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.
-
- TimeModel
Installing
pip install unic
How to
- See the UserGuide.
Example
Time Unit
TimeModel
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
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
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
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")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
unic-2.0.1.tar.gz
(8.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
unic-2.0.1-py3-none-any.whl
(14.0 kB
view details)
File details
Details for the file unic-2.0.1.tar.gz.
File metadata
- Download URL: unic-2.0.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.1 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dadb89c4a2a1bfa5127d2d7daa1e23d83701b1af316514419772f603abb0d200
|
|
| MD5 |
31e515d2ca14978b389277bb10a61cd6
|
|
| BLAKE2b-256 |
b4b289da0bbff904ca3896831b437ea878faaf99731a03d3160297a86493de54
|
File details
Details for the file unic-2.0.1-py3-none-any.whl.
File metadata
- Download URL: unic-2.0.1-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.1 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcf942ead509b30e82e2cd01f2b609a527b503844eb790b50ba5e666d0ecbef2
|
|
| MD5 |
72aa65764b03823cec9a1c402c730f00
|
|
| BLAKE2b-256 |
4d063ebb6f2dde61f321b09a21942d065c61806dbac8cd8570ce67190882876c
|