eday


Nameeday JSON
Version 1.0.7 PyPI version JSON
download
home_pagehttps://github.com/mindey/eday
SummaryA package for converting between dates and epoch days
upload_time2024-02-25 06:03:05
maintainer
docs_urlNone
authorMindey
requires_python
licenseMIT
keywords epoch days date time datetime conversion utility
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            eday
====

The `eday` package provides functions for converting between dates and epoch days.

Epoch days represent the number of days since the Unix epoch (January 1, 1970, UTC).

Installation
------------

You can install `eday` using pip:

.. code:: bash

    pip install eday

Usage
-----

The package provides three main functions:

1. `from_date`: Converts a date object or ISO format string to an equivalent number of days since the epoch.
2. `to_date`: Converts a number of days since the epoch to a datetime object in UTC.
3. `now`: Returns the current UTC time as a number of days since the epoch.

Example usage:

.. code:: python

    import eday
    import datetime

    date = datetime.datetime(1968, 12, 31)

    # Convert a date to epoch days
    eday.from_date(date) # float

    # Convert epoch days to a datetime object
    eday.to_date(20000) # datetime

    # Get the current UTC time in epoch days
    eday.now()


Shorthands
----------

The package presents a converter aliased to package, that inherits from `float`, making the computations of date differences easier.

.. code:: python

    import eday

    # Create from Epoch days
    eday(12345.67890)

    # Create from ISO dates
    eday('2003-10-20 09:17:36.96-07:00')

    # Subtract or add dates:
    eday('2024-10-04') - eday.now()

    # Create from number of hours, minutes, seconds
    eday('198:30:15.445') # (translates as 198 hours, 30 minutes, 15.445 seconds)

    # Subtract or add times:
    eday('25:50') + eday('-0:05')  # (25:50 translates into 25 hours 50 minutes)

    # Use unrestricted amounts
    eday('100:100:100.1') # (translates to 100 hours, 100 minutes, 100.1 seconds)


Negative times (experimental)
-----------------------------

Adding minus symbol ('-') and/or ('N') symbol to ISOString works currently like so:

.. code:: python

    # If "-" is prepended, then days since 1970-01-01 get mirrored around 1970-01-01
    eday('-2024-10-04') # negative number of days in [1970-01-01, 2024-10-04]

    # If "N" is added, then number of days since 0001-01-01 are returned.
    eday('N2024-10-04') # positive number of days in [0001-01-01, 2024-10-04]

    # If "-" and "N' is added, then days sine 0001-01-01 get mirrored around 0001-01-01
    eday('-N2024-10-04') # negative number of days in [-2024-10-04, 1970-01-01]

However, this behavior is experimental, and may be updated in the future.

Limitations
-----------

When using "N" prefix, negative days are mirrored, so B.C.E. seasons get inversed. This is something that in the future version we might fix, but it is not in the short term horizon.


Compatibility
--------------

The package is compatible with Python 2 (up to version 1.0.1) and Python 3 (from version 1.0.2). Under Python2, it relies on the `dateutil` module for Python 2 compatibility when parsing ISO format strings.

Using Epoch Days from Terminal
-------------------------------

Linux users can also use the following `zsh <https://ohmyz.sh/>`_ functions directly from the terminal to compute epoch days.

.. code-block:: bash

    #!/bin/zsh
    function eday { # eday now
     local n=$((($(date +%s%9N)/864)*1000))
     local day=${n:0:-14}; local hour=${n:(-14)}
     echo $day.${hour:0:${1-11}} # $1: precision
    }

    function d2e { # isodate -> eday
     local n=$((($(date -u --date="$1" +%s%9N)/864)*1000))
     local day=${n:0:-14}; local hour=${n:(-14)}
     echo $day.${hour} | sed 's/\.\?0*$//'
    }

    function e2d { # eday -> isodate
     local second=$(printf "%f" $(($1*86400)))
     echo $(date -u +"%Y-%m-%dT%H:%M:%S.%N%:z" -d "@$second")
    }

To use these functions, save them in a file named `eday.sh` and source the file to make the functions available in your terminal session.

License
-------

This package is licensed under the MIT License. See the LICENSE file for details.

Contributing
------------

Contributions are welcome! Feel free to open an issue or submit a pull request on GitHub.

GitHub Repository
------------------

You can find the source code and contribute to the development of this package on GitHub: https://github.com/mindey/eday

More Information
----------------

For more information on epoch days and their applications, you can visit the following link:

- `Simple Decimal Calendar <https://www.wefindx.com/event/17001/simple-decimal-calendar>`_

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mindey/eday",
    "name": "eday",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "epoch days date time datetime conversion utility",
    "author": "Mindey",
    "author_email": "mindey@mindey.com",
    "download_url": "",
    "platform": null,
    "description": "eday\n====\n\nThe `eday` package provides functions for converting between dates and epoch days.\n\nEpoch days represent the number of days since the Unix epoch (January 1, 1970, UTC).\n\nInstallation\n------------\n\nYou can install `eday` using pip:\n\n.. code:: bash\n\n    pip install eday\n\nUsage\n-----\n\nThe package provides three main functions:\n\n1. `from_date`: Converts a date object or ISO format string to an equivalent number of days since the epoch.\n2. `to_date`: Converts a number of days since the epoch to a datetime object in UTC.\n3. `now`: Returns the current UTC time as a number of days since the epoch.\n\nExample usage:\n\n.. code:: python\n\n    import eday\n    import datetime\n\n    date = datetime.datetime(1968, 12, 31)\n\n    # Convert a date to epoch days\n    eday.from_date(date) # float\n\n    # Convert epoch days to a datetime object\n    eday.to_date(20000) # datetime\n\n    # Get the current UTC time in epoch days\n    eday.now()\n\n\nShorthands\n----------\n\nThe package presents a converter aliased to package, that inherits from `float`, making the computations of date differences easier.\n\n.. code:: python\n\n    import eday\n\n    # Create from Epoch days\n    eday(12345.67890)\n\n    # Create from ISO dates\n    eday('2003-10-20 09:17:36.96-07:00')\n\n    # Subtract or add dates:\n    eday('2024-10-04') - eday.now()\n\n    # Create from number of hours, minutes, seconds\n    eday('198:30:15.445') # (translates as 198 hours, 30 minutes, 15.445 seconds)\n\n    # Subtract or add times:\n    eday('25:50') + eday('-0:05')  # (25:50 translates into 25 hours 50 minutes)\n\n    # Use unrestricted amounts\n    eday('100:100:100.1') # (translates to 100 hours, 100 minutes, 100.1 seconds)\n\n\nNegative times (experimental)\n-----------------------------\n\nAdding minus symbol ('-') and/or ('N') symbol to ISOString works currently like so:\n\n.. code:: python\n\n    # If \"-\" is prepended, then days since 1970-01-01 get mirrored around 1970-01-01\n    eday('-2024-10-04') # negative number of days in [1970-01-01, 2024-10-04]\n\n    # If \"N\" is added, then number of days since 0001-01-01 are returned.\n    eday('N2024-10-04') # positive number of days in [0001-01-01, 2024-10-04]\n\n    # If \"-\" and \"N' is added, then days sine 0001-01-01 get mirrored around 0001-01-01\n    eday('-N2024-10-04') # negative number of days in [-2024-10-04, 1970-01-01]\n\nHowever, this behavior is experimental, and may be updated in the future.\n\nLimitations\n-----------\n\nWhen using \"N\" prefix, negative days are mirrored, so B.C.E. seasons get inversed. This is something that in the future version we might fix, but it is not in the short term horizon.\n\n\nCompatibility\n--------------\n\nThe package is compatible with Python 2 (up to version 1.0.1) and Python 3 (from version 1.0.2). Under Python2, it relies on the `dateutil` module for Python 2 compatibility when parsing ISO format strings.\n\nUsing Epoch Days from Terminal\n-------------------------------\n\nLinux users can also use the following `zsh <https://ohmyz.sh/>`_ functions directly from the terminal to compute epoch days.\n\n.. code-block:: bash\n\n    #!/bin/zsh\n    function eday { # eday now\n     local n=$((($(date +%s%9N)/864)*1000))\n     local day=${n:0:-14}; local hour=${n:(-14)}\n     echo $day.${hour:0:${1-11}} # $1: precision\n    }\n\n    function d2e { # isodate -> eday\n     local n=$((($(date -u --date=\"$1\" +%s%9N)/864)*1000))\n     local day=${n:0:-14}; local hour=${n:(-14)}\n     echo $day.${hour} | sed 's/\\.\\?0*$//'\n    }\n\n    function e2d { # eday -> isodate\n     local second=$(printf \"%f\" $(($1*86400)))\n     echo $(date -u +\"%Y-%m-%dT%H:%M:%S.%N%:z\" -d \"@$second\")\n    }\n\nTo use these functions, save them in a file named `eday.sh` and source the file to make the functions available in your terminal session.\n\nLicense\n-------\n\nThis package is licensed under the MIT License. See the LICENSE file for details.\n\nContributing\n------------\n\nContributions are welcome! Feel free to open an issue or submit a pull request on GitHub.\n\nGitHub Repository\n------------------\n\nYou can find the source code and contribute to the development of this package on GitHub: https://github.com/mindey/eday\n\nMore Information\n----------------\n\nFor more information on epoch days and their applications, you can visit the following link:\n\n- `Simple Decimal Calendar <https://www.wefindx.com/event/17001/simple-decimal-calendar>`_\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A package for converting between dates and epoch days",
    "version": "1.0.7",
    "project_urls": {
        "Homepage": "https://github.com/mindey/eday"
    },
    "split_keywords": [
        "epoch",
        "days",
        "date",
        "time",
        "datetime",
        "conversion",
        "utility"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86e2b79ac63ff7578781c7e447fcdee10fa809395558041d77dd616912b74bd4",
                "md5": "106323e61195cbe37a2d3f3286550705",
                "sha256": "6cf8172e017cf3376d1e2ab6d174a7f8a1d1e44210f5e4b87ec00266c3e95f4f"
            },
            "downloads": -1,
            "filename": "eday-1.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "106323e61195cbe37a2d3f3286550705",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6260,
            "upload_time": "2024-02-25T06:03:05",
            "upload_time_iso_8601": "2024-02-25T06:03:05.453197Z",
            "url": "https://files.pythonhosted.org/packages/86/e2/b79ac63ff7578781c7e447fcdee10fa809395558041d77dd616912b74bd4/eday-1.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-25 06:03:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mindey",
    "github_project": "eday",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "eday"
}
        
Elapsed time: 0.19679s