eday


Nameeday JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/mindey/eday
SummaryA package for converting between dates and epoch days
upload_time2024-09-26 05:57:57
maintainerNone
docs_urlNone
authorMindey
requires_python>=3.5
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, a concept where dates are represented as the number of days since a reference epoch. This is useful for date arithmetic and conversion.

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

Install `eday` using pip:

.. code:: bash

    pip install eday

Principle
---------

Method signature.

.. code:: python

    import eday

    eday(<datetime.datetime> | '<ISO-STRING>' | '<TIME-STRING>' | <float|int>) # -> Eday <float>

    eday.from_jd(<float>) # -> Eday <float>

    eday.now() # -> Eday <float>

    eday.to_date() # -> datetime.datetime

    eday.to_jd() # -> <float> (Julian day)

Usage
------

The imoprted ``eday`` can be called directly, and supports polymorphic creation from diferent types, and simple arithmetic.

.. code:: python

    import eday

    # Create from float
    eday(0) # 0.0 <1970-01-01 00:00:00+00:00>

    # Passing large numbers displays date representations as well
    eday(-2440587.5) # -2440587.5 <-4713-11-24 12:00:0.000000 UTC>

    # Create from datetime.datetime
    eday(datetime.datetime(1970,1,1))

    # Create from ISO dates
    eday('1969-12-31 17:00:00-07:00')

    # Create from Time string
    eday('-7:00') # 7 hours before "epoch 0". NOTE: If '-' is before ISO 8610 string, it means BC (before common era.)

    # Unrestricted float numbers of hours, minutes, seconds can be used
    eday('100.5:100.15:100.125') # (100.5 hours, 100.15 minutes, 100.125 seconds)

    # Create from Julian days:
    eday.from_jd(2459580.5) # 18993.0 <2022-01-01T00:00:00+00:00>

    # Date arithmetic
    eday('2024-10-04') - eday.now()

    # Time arithmetic
    eday('1:50') - eday('0:10:15.123')  # (1 hour 50 minutes - 10 minutes 15.123 seconds)

    # Convert to Julian day
    eday('2024-10-04').to_jd() # 2460587.5

    # Format as decimal unix day and time, for viewing as date and time string.
    eday('2024-10-04 12:15').format() # 20,000 T 5:10:41.6666668


About
-----
The ``eday`` package features the ``Eday`` class, which represents "epoch days" (Unix seconds in days). It inherits from ``float``, providing conversions to/from datetime, and supports arithmetic operations for quick date calculations.

Main Functions:

1. ``from_date``: Converts a date object or ISO format string to the number of days since the epoch.
2. ``from_jd``: Convets Julian day to number of days since the epoch.
3. ``now``: Returns the current UTC time as a number of days since the epoch.

Auxiliary Functions:

4. ``to_date``: Converts Eday object to ``datetime.datetime`` if possible.
5. ``to_jd``: Converts Eday object to Julian day.

Miscellanous Functions:

6. ``format``: Formats Eday as Decimal Unix day and time in a fashion similar to ``datetime.datetime.isoformat()``.

However, you can call the imported ``eday`` directly (as shown in the examples above) to use it with minimal typing to do time and calendar computations.


Using Epoch Days without this package (Python 2 & Python 3)
-----------------------------------------------------------
If you don't need these extra features, and just need to convert dates to/from edays, you could simply use:

.. code:: python

    import time, datetime

    def d2e(date): # datetime.datetime -> float
        return time.mktime(date.utctimetuple()) / 86400.

    def e2d(eday): # datetime.datetime -> float
        return datetime.datetime.utcfromtimestamp(eday * 86400.)

    def eday():
        return d2e(datetime.datetime.utcnow())

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

Linux users can use these ``zsh`` functions:

.. code-block:: bash

    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")
    }

Save these functions in ``eday.sh`` and source it or add to ``/usr/local/bin/eday``.

.. code-block:: bash

    #!/bin/bash
    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
    }
    eday

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

The package is compatible with Python 2 (up to version 1.0.1) and Python 3 (from version 1.0.2). Python 2 users will need the ``dateutil`` module for parsing ISO format strings.

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": null,
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": null,
    "keywords": "epoch days date time datetime conversion utility",
    "author": "Mindey",
    "author_email": "mindey@mindey.com",
    "download_url": null,
    "platform": null,
    "description": "eday\n====\n\nThe ``eday`` package provides functions for converting between dates and epoch days, a concept where dates are represented as the number of days since a reference epoch. This is useful for date arithmetic and conversion.\n\nInstallation\n------------\n\nInstall `eday` using pip:\n\n.. code:: bash\n\n    pip install eday\n\nPrinciple\n---------\n\nMethod signature.\n\n.. code:: python\n\n    import eday\n\n    eday(<datetime.datetime> | '<ISO-STRING>' | '<TIME-STRING>' | <float|int>) # -> Eday <float>\n\n    eday.from_jd(<float>) # -> Eday <float>\n\n    eday.now() # -> Eday <float>\n\n    eday.to_date() # -> datetime.datetime\n\n    eday.to_jd() # -> <float> (Julian day)\n\nUsage\n------\n\nThe imoprted ``eday`` can be called directly, and supports polymorphic creation from diferent types, and simple arithmetic.\n\n.. code:: python\n\n    import eday\n\n    # Create from float\n    eday(0) # 0.0 <1970-01-01 00:00:00+00:00>\n\n    # Passing large numbers displays date representations as well\n    eday(-2440587.5) # -2440587.5 <-4713-11-24 12:00:0.000000 UTC>\n\n    # Create from datetime.datetime\n    eday(datetime.datetime(1970,1,1))\n\n    # Create from ISO dates\n    eday('1969-12-31 17:00:00-07:00')\n\n    # Create from Time string\n    eday('-7:00') # 7 hours before \"epoch 0\". NOTE: If '-' is before ISO 8610 string, it means BC (before common era.)\n\n    # Unrestricted float numbers of hours, minutes, seconds can be used\n    eday('100.5:100.15:100.125') # (100.5 hours, 100.15 minutes, 100.125 seconds)\n\n    # Create from Julian days:\n    eday.from_jd(2459580.5) # 18993.0 <2022-01-01T00:00:00+00:00>\n\n    # Date arithmetic\n    eday('2024-10-04') - eday.now()\n\n    # Time arithmetic\n    eday('1:50') - eday('0:10:15.123')  # (1 hour 50 minutes - 10 minutes 15.123 seconds)\n\n    # Convert to Julian day\n    eday('2024-10-04').to_jd() # 2460587.5\n\n    # Format as decimal unix day and time, for viewing as date and time string.\n    eday('2024-10-04 12:15').format() # 20,000 T 5:10:41.6666668\n\n\nAbout\n-----\nThe ``eday`` package features the ``Eday`` class, which represents \"epoch days\" (Unix seconds in days). It inherits from ``float``, providing conversions to/from datetime, and supports arithmetic operations for quick date calculations.\n\nMain Functions:\n\n1. ``from_date``: Converts a date object or ISO format string to the number of days since the epoch.\n2. ``from_jd``: Convets Julian day to number of days since the epoch.\n3. ``now``: Returns the current UTC time as a number of days since the epoch.\n\nAuxiliary Functions:\n\n4. ``to_date``: Converts Eday object to ``datetime.datetime`` if possible.\n5. ``to_jd``: Converts Eday object to Julian day.\n\nMiscellanous Functions:\n\n6. ``format``: Formats Eday as Decimal Unix day and time in a fashion similar to ``datetime.datetime.isoformat()``.\n\nHowever, you can call the imported ``eday`` directly (as shown in the examples above) to use it with minimal typing to do time and calendar computations.\n\n\nUsing Epoch Days without this package (Python 2 & Python 3)\n-----------------------------------------------------------\nIf you don't need these extra features, and just need to convert dates to/from edays, you could simply use:\n\n.. code:: python\n\n    import time, datetime\n\n    def d2e(date): # datetime.datetime -> float\n        return time.mktime(date.utctimetuple()) / 86400.\n\n    def e2d(eday): # datetime.datetime -> float\n        return datetime.datetime.utcfromtimestamp(eday * 86400.)\n\n    def eday():\n        return d2e(datetime.datetime.utcnow())\n\nUsing Epoch Days from Terminal\n-------------------------------\n\nLinux users can use these ``zsh`` functions:\n\n.. code-block:: bash\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\nSave these functions in ``eday.sh`` and source it or add to ``/usr/local/bin/eday``.\n\n.. code-block:: bash\n\n    #!/bin/bash\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    eday\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). Python 2 users will need the ``dateutil`` module for parsing ISO format strings.\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.1.0",
    "project_urls": {
        "Homepage": "https://github.com/mindey/eday"
    },
    "split_keywords": [
        "epoch",
        "days",
        "date",
        "time",
        "datetime",
        "conversion",
        "utility"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5f16bc95b6ea49938e4140542cfb28f82e27906fa432546ca91c237c9698cb34",
                "md5": "f372437b93484d72b2063c8ffe45abdb",
                "sha256": "c0c6b1abe8cf6124e6ed78148e78834d163d0db0a33eb4cbd906b54d82fe6e4e"
            },
            "downloads": -1,
            "filename": "eday-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f372437b93484d72b2063c8ffe45abdb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 7422,
            "upload_time": "2024-09-26T05:57:57",
            "upload_time_iso_8601": "2024-09-26T05:57:57.187062Z",
            "url": "https://files.pythonhosted.org/packages/5f/16/bc95b6ea49938e4140542cfb28f82e27906fa432546ca91c237c9698cb34/eday-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-26 05:57:57",
    "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: 5.00049s