home.social

#pytz — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #pytz, aggregated by home.social.

  1. @astraluma

    It depends on what, exactly, you want. time.localtime() will give you a value in the system's configured #timezone. time.gmtime() will give you #UTC. The difference between those will tell you the current local time's offset from UTC.

    If you want the name of the configured timezone, on many Unix-type systems, you can read /etc/timezone to get it.

    If you want more specific info about a timezone, you can add an external dependency which includes (or provides access to a system-provided) database of timezone info. This stuff changes often, and is decided politically rather than technically, so it's a moving target and the #Python #stdlib doesn't try to include it. `pytz` is one such package with a fairly complete database.

    And you can easily override any of these in a test framework. Using unittest.mock.MagicMock(), for example, lets you override any of the above with whatever value you want those functions to return.

    #pytz #test #mock #MagicMock

  2. @astraluma

    It depends on what, exactly, you want. time.localtime() will give you a value in the system's configured #timezone. time.gmtime() will give you #UTC. The difference between those will tell you the current local time's offset from UTC.

    If you want the name of the configured timezone, on many Unix-type systems, you can read /etc/timezone to get it.

    If you want more specific info about a timezone, you can add an external dependency which includes (or provides access to a system-provided) database of timezone info. This stuff changes often, and is decided politically rather than technically, so it's a moving target and the #Python #stdlib doesn't try to include it. `pytz` is one such package with a fairly complete database.

    And you can easily override any of these in a test framework. Using unittest.mock.MagicMock(), for example, lets you override any of the above with whatever value you want those functions to return.

    #pytz #test #mock #MagicMock

  3. @astraluma

    It depends on what, exactly, you want. time.localtime() will give you a value in the system's configured #timezone. time.gmtime() will give you #UTC. The difference between those will tell you the current local time's offset from UTC.

    If you want the name of the configured timezone, on many Unix-type systems, you can read /etc/timezone to get it.

    If you want more specific info about a timezone, you can add an external dependency which includes (or provides access to a system-provided) database of timezone info. This stuff changes often, and is decided politically rather than technically, so it's a moving target and the #Python #stdlib doesn't try to include it. `pytz` is one such package with a fairly complete database.

    And you can easily override any of these in a test framework. Using unittest.mock.MagicMock(), for example, lets you override any of the above with whatever value you want those functions to return.

    #pytz #test #mock #MagicMock

  4. @astraluma

    It depends on what, exactly, you want. time.localtime() will give you a value in the system's configured #timezone. time.gmtime() will give you #UTC. The difference between those will tell you the current local time's offset from UTC.

    If you want the name of the configured timezone, on many Unix-type systems, you can read /etc/timezone to get it.

    If you want more specific info about a timezone, you can add an external dependency which includes (or provides access to a system-provided) database of timezone info. This stuff changes often, and is decided politically rather than technically, so it's a moving target and the #Python #stdlib doesn't try to include it. `pytz` is one such package with a fairly complete database.

    And you can easily override any of these in a test framework. Using unittest.mock.MagicMock(), for example, lets you override any of the above with whatever value you want those functions to return.

    #pytz #test #mock #MagicMock

  5. @astraluma

    It depends on what, exactly, you want. time.localtime() will give you a value in the system's configured #timezone. time.gmtime() will give you #UTC. The difference between those will tell you the current local time's offset from UTC.

    If you want the name of the configured timezone, on many Unix-type systems, you can read /etc/timezone to get it.

    If you want more specific info about a timezone, you can add an external dependency which includes (or provides access to a system-provided) database of timezone info. This stuff changes often, and is decided politically rather than technically, so it's a moving target and the #Python #stdlib doesn't try to include it. `pytz` is one such package with a fairly complete database.

    And you can easily override any of these in a test framework. Using unittest.mock.MagicMock(), for example, lets you override any of the above with whatever value you want those functions to return.

    #pytz #test #mock #MagicMock

  6. I'm deep into rolling forward my long-term #Django project from the 3.2 LTS. The target is to get all the way to 4.2.9 LTS before next weekend.

    I've already successfully worked through several utility dependency problems.

    Now for the biggie: moving from #pytz to #zoneinfo: docs.djangoproject.com/en/5.0/

    Currently, this looks rather daunting...