/ README.rst
README.rst
1 Introduction 2 ============ 3 4 .. image:: https://readthedocs.org/projects/adafruit-circuitpython-datetime/badge/?version=latest 5 :target: https://circuitpython.readthedocs.io/projects/datetime/en/latest/ 6 :alt: Documentation Status 7 8 .. image:: https://img.shields.io/discord/327254708534116352.svg 9 :target: https://adafru.it/discord 10 :alt: Discord 11 12 .. image:: https://github.com/adafruit/Adafruit_CircuitPython_datetime/workflows/Build%20CI/badge.svg 13 :target: https://github.com/adafruit/Adafruit_CircuitPython_datetime/actions 14 :alt: Build Status 15 16 .. image:: https://img.shields.io/badge/code%20style-black-000000.svg 17 :target: https://github.com/psf/black 18 :alt: Code Style: Black 19 20 Basic date and time types. Implements a subset of the `CPython datetime module <https://docs.python.org/3/library/datetime.html>`_. 21 22 NOTE: This library has a large memory footprint and is intended for hardware such as the SAMD51, ESP32-S2, and nRF52. 23 24 Dependencies 25 ============= 26 This driver depends on: 27 28 * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ 29 30 Please ensure all dependencies are available on the CircuitPython filesystem. 31 This is easily achieved by downloading 32 `the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_. 33 34 Installing from PyPI 35 ===================== 36 On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 37 PyPI <https://pypi.org/project/adafruit-circuitpython-datetime/>`_. To install for current user: 38 39 .. code-block:: shell 40 41 pip3 install adafruit-circuitpython-datetime 42 43 To install system-wide (this may be required in some cases): 44 45 .. code-block:: shell 46 47 sudo pip3 install adafruit-circuitpython-datetime 48 49 To install in a virtual environment in your current project: 50 51 .. code-block:: shell 52 53 mkdir project-name && cd project-name 54 python3 -m venv .env 55 source .env/bin/activate 56 pip3 install adafruit-circuitpython-datetime 57 58 Usage Example 59 ============= 60 61 .. code-block:: python 62 63 # Example of working with a `datetime` object 64 # from https://docs.python.org/3/library/datetime.html#examples-of-usage-datetime 65 from adafruit_datetime import datetime, date, time, timezone 66 67 # Using datetime.combine() 68 d = date(2005, 7, 14) 69 print(d) 70 t = time(12, 30) 71 print(datetime.combine(d, t)) 72 73 # Using datetime.now() 74 print("Current time (GMT +1):", datetime.now()) 75 print("Current UTC time: ", datetime.now(timezone.utc)) 76 77 # Using datetime.timetuple() to get tuple of all attributes 78 dt = datetime(2006, 11, 21, 16, 30) 79 tt = dt.timetuple() 80 for it in tt: 81 print(it) 82 83 # Formatting a datetime 84 print( 85 "The {1} is {0:%d}, the {2} is {0:%B}, the {3} is {0:%I:%M%p}.".format( 86 dt, "day", "month", "time" 87 ) 88 ) 89 90 Contributing 91 ============ 92 93 Contributions are welcome! Please read our `Code of Conduct 94 <https://github.com/adafruit/Adafruit_CircuitPython_datetime/blob/master/CODE_OF_CONDUCT.md>`_ 95 before contributing to help this project stay welcoming. 96 97 Documentation 98 ============= 99 100 For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_. 101 102 License 103 ======= 104 See LICENSE/ for details. 105 106 Copyright (c) 2001-2021 Python Software Foundation. All rights reserved. 107 108 Copyright (c) 2000 BeOpen.com. All rights reserved. 109 110 Copyright (c) 1995-2001 Corporation for National Research Initiatives. All rights reserved. 111 112 Copyright (c) 1991-1995 Stichting Mathematisch Centrum. All rights reserved.