Skip to main content

This is an astral wrapper, that adds functionality for getting the part of day for a spesific datetime.

Project description

Part of Day

This is an astral package wrapper, that uses it's calculations to give the part of day, instead of giving time intervals for spesific parts.

Installation

To install, run the following command

pip install part-of-day

Usage

from part_of_day import PartOfDayCalculator

from datetime import datetime, timezone

pod = PartOfDayCalculator(latitude=15.33, longitude=-7)

# following methods gives results related to now, if a datetime is not given
pod.is_it_day()
# True
pod.is_it_night()
# False
pod.get_part_of_day()
# <PartOfDay.DAY: 'Day'>

# or they can be used with a datetime
dt = datetime(2025, 3, 12, 6, 13, 25, 0, timezone.utc)

pod.is_it_day(dt)
# False
pod.is_it_night(dt)
# True
pod.get_part_of_day(dt)
# <PartOfDay.NIGHT: 'Night'>

Including twilights

By settings include_twilights flag in calculator's init, you can enable calculations for dusk and dawn (normally, both counts as night). Note that, if you do it, you should use PartOfDayWithTwilights enum in equality checks, and vice versa, in order to avoid incorrect equalities.

from part_of_day import PartOfDayCalculator, PartOfDayWithTwilights, PartOfDay

from datetime import datetime, timezone

pod = PartOfDayCalculator(latitude=15.33, longitude=-7, include_twilights=True)

# following methods gives results related to now, if a datetime is not given
pod.is_it_day()
# True
pod.is_it_night()
# False
pod.is_it_dawn()
# False
pod.is_it_dusk()
# False
pod.get_part_of_day()
# <PartOfDayWithTwilights.DAY: 'Day'>
pod.get_part_of_day() == PartOfDayWithTwilights.NIGHT
# False
pod.get_part_of_day()==PartOfDay.NIGHT
# part_of_day.exceptions.MixedPartOfDayError: Checking equality between <PartOfDay> and <PartOfDayWithTwilights> enums could cause miscalculations. Please use <PartOfDayWithTwilights> enum if "include_twilights" is enabled

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

part_of_day-0.4.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

part_of_day-0.4.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file part_of_day-0.4.0.tar.gz.

File metadata

  • Download URL: part_of_day-0.4.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.10.12 Linux/6.14.0-33-generic

File hashes

Hashes for part_of_day-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f26360a77a83b25737494b9677c452b01a3327b505824fc381b8602f542d0670
MD5 b4cec4411d25f84ba5d998cc617ab2eb
BLAKE2b-256 3fcc49f855183ec6792b4c0b8438d21dca01e9d976eb928c6b1252104c021d8c

See more details on using hashes here.

File details

Details for the file part_of_day-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: part_of_day-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.10.12 Linux/6.14.0-33-generic

File hashes

Hashes for part_of_day-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 520263f02bdfdfd8ea67f44b42bb7a657215d9c3437fd97bbfef09caf233ec08
MD5 fa65391f4fd7e6493c3f4008fb0864d6
BLAKE2b-256 f88fbff1dc5bc777cd7b45f46a9d5f21c01cf59160663869383b60d3a226f6ac

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