HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/blueprints/sysadmin/utilities/utc_to_timezone.py
from datetime import datetime
from pytz import timezone, utc


class FromUTC:
    @staticmethod
    def get_est_now():
        # Get the current UTC time
        utc_now = datetime.utcnow()
        # Create a timezone object for EST
        est_tz = timezone('US/Eastern')
        # Convert the UTC time to EST
        return utc_now.replace(tzinfo=utc).astimezone(est_tz)

    @staticmethod
    def get_timezone_now(tz: str):
        # Get the current UTC time
        utc_now = datetime.utcnow()
        # Create a timezone object for tz
        target_tz = timezone(tz)
        # Convert the UTC time to tz
        return utc_now.replace(tzinfo=utc).astimezone(target_tz)

    @staticmethod
    def get_est_custom_date(date_time):
        # Create a timezone object for EST
        est_tz = timezone('US/Eastern')
        # Convert the UTC time to EST
        return date_time.replace(tzinfo=utc).astimezone(est_tz)