Skip to main content

Python package to work with NTP servers, time zones, and localized names of months and days of the week.

Project description

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Datetime Toolkit

Python package to work with NTP servers, time zones, and localized names of months and days of the week.

Report Bug · Request Feature

Table of Contents
  1. 🏁 Getting Started
  2. ✨ Usage
  3. 🤝🏼 Contributing
  4. 📜️️ License
  5. 📬 Contact
  6. 🙏🏼 Acknowledgments

🏁 Getting Started

Prerequisites

  • Python 3

Installation

Using pip

pip install datetime_toolkit

(back to top)

✨ Usage

Default instantation

Default parameters are from 🇨🇱 Chile:

  • NTP Server: ntp.shoa.cl
  • Time zone: America / Santiago
  • Locale: Your system default locale

To use custom locale, the language must be installed on your system. On Linux, check your /etc/locale.gen file. For example, I have English, Spanish and German installed.

grep -v "#" /etc/locale.gen

en_US.UTF-8 UTF-8
es_CL.UTF-8 UTF-8
de_DE.UTF-8 UTF-8
datetime_toolkit = DatetimeToolkit(locale = 'es_CL.UTF-8')
print(datetime_toolkit.months)
print(datetime_toolkit.days)

# Printed values
['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']
['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo']

Custom instantation

To use custom parameters, use the country ISO 3166 alpha-2 code to find your country information.

For example, the country code for 🇩🇪 Germany is "DE", so you can use:

info = DatetimeToolkit.country_information(alpha_2_code = 'de')

# Static method country_information(code) will return a dictionary like this
info = {'country': 'Germany', 'time_zones': ['Europe/Berlin', 'Europe/Busingen']}

I will use PTB NTP server (ptbtime1.ptb.de) and the timezone from Berlin.

datetime_toolkit = DatetimeToolkit(ntp = 'ptbtime1.ptb.de', tz = 'Europe/Berlin', locale = 'de_DE.UTF-8')
print(datetime_toolkit.months)
print(datetime_toolkit.days)

# Printed values
['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag']

Class DatetimeToolkit properties and methods

Property Returns
days List with the names of the days of the week as strings. Language used is determined by locale parameter or system default. First letter is uppercase and the rest lowercase.
months List with the names of the months as strings. Language used is determined by locale parameter or system default. First letter is uppercase and the rest lowercase.
Method Returns
@staticmethod
country_information(alpha_2_code: str)
Dictionary with country information. Keys are the strings "country" and "time_zones".
locale() Locale used as string. None if no locale was provided.
server_url() NTP server URL/IP as string.
tz() Object datetime.tzinfo for the given time zone.
local_time() Float timestamp of the current local time. Wrapper of time.time()
server_time() Integer timestamp of the server time.
datetime(is_request_forced = False, is_utc = False) Datetime object using given time zone.
string(is_request_forced = False, is_utc = False, string_format = '%Y-%m-%d %H:%M:%S') String representing datetime using string_format.
float_to_datetime(timestamp: float, is_utc = False) Datetime from timestamp using given time zone.
float_to_string(timestamp: float, is_utc = False, string_format = '%Y-%m-%d %H:%M:%S') String from timestamp using given time zone and string_format.
name_month(custom_datetime: datetime = None, is_request_forced = False, is_utc = False) String of the localized month name. If custom_datetime is None, it will use datetime() method.
name_day(custom_datetime: datetime = None, is_request_forced = False, is_utc = False) String of the localized day name. If custom_datetime is None, it will use datetime() method.

(back to top)

🤝🏼 Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

📜️️ License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

📬 Contact

👨🏻‍💻 Sebastián Valdivia Loyola [ ✉️ E-Mail - 📂 GitHub - 📦 Project ]

(back to top)

🙏🏼 Acknowledgments

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datetime_toolkit-1.0.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datetime_toolkit-1.0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file datetime_toolkit-1.0.1.tar.gz.

File metadata

  • Download URL: datetime_toolkit-1.0.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for datetime_toolkit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9007e3c0b733db7497133c45b35619fb08d9dd0e6c27f07debdbe45a93316668
MD5 66466ee1accfb8f27d7b98fde4e6d244
BLAKE2b-256 fd32461f6108e278ae6d4a87ebeb20850bac5dc6c82c4ff3a6f0a17a15e68ff3

See more details on using hashes here.

File details

Details for the file datetime_toolkit-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for datetime_toolkit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95d97905ed075aebf7222a0958a9aaeb8b905cafb9a6849f3b077f2b43a4d15b
MD5 a3884b9d9ec9f424412852434dff2101
BLAKE2b-256 7c6bfaf3f50c37bc66081444a3adc2c34415e270e5f6b06b627dc4ffb122bb4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page