date-time-literal


Namedate-time-literal JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/kells4real/date_literal
Summarydate-time-literal is a python module that helps convert date-time or date to literal days, hours, seconds, or even minutes. Compare two DateTime or Date objects, by converting the objects to literal days, hours, minutes, or even seconds if you want to be precise.
upload_time2023-05-05 14:53:13
maintainer
docs_urlNone
authorKelvin Sajere
requires_python>=3.5
license
keywords date-time date literal date converter literal date date-time converter django python module python package date-time literal convert time convert date-time
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # date_literal
A package/module for converting date or date-time formats to literal days, hours, minutes, or seconds for comparison or whatever. 
For example, you can convert DateTime objects to know just how much of a difference there is between them, or you just want 
to get the human-readable format of DateTime or Date objects.

## Installation
> pip install date_time_literal

## Usage
#### IMPORTANT
DateTime or Date objects must be in the default 'Y-M-D Hr:Min:Sec' and 'Y-M-D' formats respectively.

##### Converts Date Time Literal
```python
from django.utils import timezone
time = timezone.now()
from date_time_literal import ConvertTime
convert_time = ConvertTime(time).convert_time
```
##### Converts Date Literal
convert_time = ConvertTime(time).convert
This returns the date or date_time in seconds. You can add an optional parameter to specify what you want.

Note: You can use the convert class function on a DateTime object if you wish to use only the date part of the DateTime object, 
but cannot use the convert_time class function on a Date object, only on DateTime objects.

#### Specific conversion to days

```python
from django.utils import timezone
from datetime import datetime
from date_time_literal import ConvertTime

time2 = datetime.now()
time = timezone.now()

convert_time = ConvertTime(time, 'd').convert_time
convert_time2 = ConvertTime(time2, 'd').convert
```

#### Specific conversion to hours

```python
from date_time_literal import ConvertTime
from datetime import datetime
time = datetime.now()
convert_time = ConvertTime(time, 'd').convert_time # Converts the DateTime object to days
convert_time1 = ConvertTime(time, 'h').convert_time # Converts the DateTime object to hours
convert_time2 = ConvertTime(time, 'm').convert_time # Converts the DateTime object to minutes

# The default conversion if none is specified is to seconds
```

### CHECK DATE-TIME OR DATE DIFFERENCE BETWEEN TWO DATE-TIME OR DATE OBJECTS

```python
from date_time_literal import ConvertTime
from datetime import datetime
from django.utils import timezone
time = datetime.now()
convert_time = ConvertTime(time, 'h').convert_time
from date_time_literal import date_time_diff, date_diff
convert_time2 = ConvertTime(time, 'm').convert_time
date1 = '2021-05-31'
date2 = '2021-03-21'
date_time1 = timezone.now()
date_time2 = '2021-03-21 23:16:45.735963'
date_l = date_diff(date1, date2, 'd')
date_time_l = date_time_diff(date_time1, date_time2, 'd')

# date_time_l will return the difference in value between date_time1 and date_time2 in days. You can use the 
# corresponding string literal to get for minutes, hours and seconds which is the default value.
# date_time_diff returns the difference in two dateTimes to the second. This should be used when you need to get 
# date time difference to the last second

```

## Convert between time and date objects
You can also use the convert_time function to convert between times

```python
from date_time_literal import convert_time

# Converts between years, days, hours, minutes, and seconds
print(convert_time(365, 'd', 'y')) # Converts 365 days to years
print(convert_time(5, 'y', 'd')) # Converts 5 years to days
print(convert_time(5, 'y', 'h')) # Converts 5 years to hours
print(convert_time(5, 'd', 's')) # Converts 5 days to seconds
# etc
```

### Some Basic use cases
To get a rather comprehensive idea of how the package works, copy the code below and run it. The convert_time function
was updated to be more efficient and now allows for week conversion as well in version 1.0.8

```python
from date_time_literal import ConvertTime, DateDiff, date_diff, convert_time, date_time_diff
from datetime import datetime

t = ConvertTime('2021-05-31 23:16:55.321568', 'd')
p = ConvertTime(datetime.now(), 'd')
i = ConvertTime('2021-05-31 23:16:55+00:00', 'd')
d = ConvertTime('2021-05-31', time_format='d')
e = DateDiff('2021-05-31', '2021-04-31', 'd')
print(t.convert_time)
print(i.convert_time)
print(d.convert)
print(e.date_diff)
print(date_diff('2021-08-31', '2021-05-30', 'D'))
print(date_time_diff('2021-04-30 21:58:50+00:00', '2021-04-30 10:58:55+00:00', 'H'))
print(convert_time(1, "y", 'h'))
print(convert_time(365, 'd', 'y'))

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kells4real/date_literal",
    "name": "date-time-literal",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "date-time,date,literal,date converter,literal date,date-time converter,django,python,module,python package,date-time literal,convert time,convert date-time",
    "author": "Kelvin Sajere",
    "author_email": "kells4real@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0c/a9/67c85b00a7d99d451d770c7b9657e596a031929c225cac1a9efa6d55d7b7/date_time_literal-1.1.0.tar.gz",
    "platform": null,
    "description": "# date_literal\r\nA package/module for converting date or date-time formats to literal days, hours, minutes, or seconds for comparison or whatever. \r\nFor example, you can convert DateTime objects to know just how much of a difference there is between them, or you just want \r\nto get the human-readable format of DateTime or Date objects.\r\n\r\n## Installation\r\n> pip install date_time_literal\r\n\r\n## Usage\r\n#### IMPORTANT\r\nDateTime or Date objects must be in the default 'Y-M-D Hr:Min:Sec' and 'Y-M-D' formats respectively.\r\n\r\n##### Converts Date Time Literal\r\n```python\r\nfrom django.utils import timezone\r\ntime = timezone.now()\r\nfrom date_time_literal import ConvertTime\r\nconvert_time = ConvertTime(time).convert_time\r\n```\r\n##### Converts Date Literal\r\nconvert_time = ConvertTime(time).convert\r\nThis returns the date or date_time in seconds. You can add an optional parameter to specify what you want.\r\n\r\nNote: You can use the convert class function on a DateTime object if you wish to use only the date part of the DateTime object, \r\nbut cannot use the convert_time class function on a Date object, only on DateTime objects.\r\n\r\n#### Specific conversion to days\r\n\r\n```python\r\nfrom django.utils import timezone\r\nfrom datetime import datetime\r\nfrom date_time_literal import ConvertTime\r\n\r\ntime2 = datetime.now()\r\ntime = timezone.now()\r\n\r\nconvert_time = ConvertTime(time, 'd').convert_time\r\nconvert_time2 = ConvertTime(time2, 'd').convert\r\n```\r\n\r\n#### Specific conversion to hours\r\n\r\n```python\r\nfrom date_time_literal import ConvertTime\r\nfrom datetime import datetime\r\ntime = datetime.now()\r\nconvert_time = ConvertTime(time, 'd').convert_time # Converts the DateTime object to days\r\nconvert_time1 = ConvertTime(time, 'h').convert_time # Converts the DateTime object to hours\r\nconvert_time2 = ConvertTime(time, 'm').convert_time # Converts the DateTime object to minutes\r\n\r\n# The default conversion if none is specified is to seconds\r\n```\r\n\r\n### CHECK DATE-TIME OR DATE DIFFERENCE BETWEEN TWO DATE-TIME OR DATE OBJECTS\r\n\r\n```python\r\nfrom date_time_literal import ConvertTime\r\nfrom datetime import datetime\r\nfrom django.utils import timezone\r\ntime = datetime.now()\r\nconvert_time = ConvertTime(time, 'h').convert_time\r\nfrom date_time_literal import date_time_diff, date_diff\r\nconvert_time2 = ConvertTime(time, 'm').convert_time\r\ndate1 = '2021-05-31'\r\ndate2 = '2021-03-21'\r\ndate_time1 = timezone.now()\r\ndate_time2 = '2021-03-21 23:16:45.735963'\r\ndate_l = date_diff(date1, date2, 'd')\r\ndate_time_l = date_time_diff(date_time1, date_time2, 'd')\r\n\r\n# date_time_l will return the difference in value between date_time1 and date_time2 in days. You can use the \r\n# corresponding string literal to get for minutes, hours and seconds which is the default value.\r\n# date_time_diff returns the difference in two dateTimes to the second. This should be used when you need to get \r\n# date time difference to the last second\r\n\r\n```\r\n\r\n## Convert between time and date objects\r\nYou can also use the convert_time function to convert between times\r\n\r\n```python\r\nfrom date_time_literal import convert_time\r\n\r\n# Converts between years, days, hours, minutes, and seconds\r\nprint(convert_time(365, 'd', 'y')) # Converts 365 days to years\r\nprint(convert_time(5, 'y', 'd')) # Converts 5 years to days\r\nprint(convert_time(5, 'y', 'h')) # Converts 5 years to hours\r\nprint(convert_time(5, 'd', 's')) # Converts 5 days to seconds\r\n# etc\r\n```\r\n\r\n### Some Basic use cases\r\nTo get a rather comprehensive idea of how the package works, copy the code below and run it. The convert_time function\r\nwas updated to be more efficient and now allows for week conversion as well in version 1.0.8\r\n\r\n```python\r\nfrom date_time_literal import ConvertTime, DateDiff, date_diff, convert_time, date_time_diff\r\nfrom datetime import datetime\r\n\r\nt = ConvertTime('2021-05-31 23:16:55.321568', 'd')\r\np = ConvertTime(datetime.now(), 'd')\r\ni = ConvertTime('2021-05-31 23:16:55+00:00', 'd')\r\nd = ConvertTime('2021-05-31', time_format='d')\r\ne = DateDiff('2021-05-31', '2021-04-31', 'd')\r\nprint(t.convert_time)\r\nprint(i.convert_time)\r\nprint(d.convert)\r\nprint(e.date_diff)\r\nprint(date_diff('2021-08-31', '2021-05-30', 'D'))\r\nprint(date_time_diff('2021-04-30 21:58:50+00:00', '2021-04-30 10:58:55+00:00', 'H'))\r\nprint(convert_time(1, \"y\", 'h'))\r\nprint(convert_time(365, 'd', 'y'))\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "date-time-literal is a python module that helps convert date-time or date to literal days, hours, seconds, or even minutes. Compare two DateTime or Date objects, by converting the objects to literal days, hours, minutes, or even seconds if you want to be precise.",
    "version": "1.1.0",
    "project_urls": {
        "Download": "https://github.com/kells4real/date_literal/archive/refs/tags/1.0.0.tar.gz",
        "Homepage": "https://github.com/kells4real/date_literal"
    },
    "split_keywords": [
        "date-time",
        "date",
        "literal",
        "date converter",
        "literal date",
        "date-time converter",
        "django",
        "python",
        "module",
        "python package",
        "date-time literal",
        "convert time",
        "convert date-time"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf58520840c4327d0b19e48b45615e1b500a45e0c9196e712b74efea7bf00f8e",
                "md5": "4f123bd369a754a2c62a0c183ef909bb",
                "sha256": "7a1ccc013482b5ca28efc776d92aeab8bc3d2a6a1ae067fe055000d20b80dee6"
            },
            "downloads": -1,
            "filename": "date_time_literal-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f123bd369a754a2c62a0c183ef909bb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 5998,
            "upload_time": "2023-05-05T14:52:22",
            "upload_time_iso_8601": "2023-05-05T14:52:22.737918Z",
            "url": "https://files.pythonhosted.org/packages/bf/58/520840c4327d0b19e48b45615e1b500a45e0c9196e712b74efea7bf00f8e/date_time_literal-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0ca967c85b00a7d99d451d770c7b9657e596a031929c225cac1a9efa6d55d7b7",
                "md5": "3415bb316f48cbdf70c55b411897cb03",
                "sha256": "8aa15ae3f0b0b75238cafc55d5f9fe4b1455bbebecc9e0e9991d76b0847b38b4"
            },
            "downloads": -1,
            "filename": "date_time_literal-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3415bb316f48cbdf70c55b411897cb03",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 5244,
            "upload_time": "2023-05-05T14:53:13",
            "upload_time_iso_8601": "2023-05-05T14:53:13.693419Z",
            "url": "https://files.pythonhosted.org/packages/0c/a9/67c85b00a7d99d451d770c7b9657e596a031929c225cac1a9efa6d55d7b7/date_time_literal-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-05 14:53:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kells4real",
    "github_project": "date_literal",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "date-time-literal"
}
        
Elapsed time: 0.70697s