Download components/utils/utils.py from heboya8/ETL_pipeline: direct link, hf CLI and curl.
- Browser
- Download file 797 Bytes
-
https://huggingface.co/heboya8/ETL_pipeline/resolve/main/components/utils/utils.py
- Command line
-
hf download hf://heboya8/ETL_pipeline/components/utils/utils.py
-
curl -L -o utils.py https://huggingface.co/heboya8/ETL_pipeline/resolve/main/components/utils/utils.py
797 Bytes
| from datetime import timezone, timedelta | |
| import re | |
| def parse_timezone(tz_offset_str): | |
| """ | |
| Parse a timezone offset string (e.g., '+07:00') and return a timezone object. | |
| Args: | |
| tz_offset_str (str): Timezone offset in format '[+-]HH:MM' | |
| Returns: | |
| timezone: A datetime.timezone object with the specified offset | |
| Raises: | |
| ValueError: If the timezone format is invalid | |
| """ | |
| match = re.match(r'([+-])(\d{2}):(\d{2})', tz_offset_str) | |
| if not match: | |
| raise ValueError(f"Invalid timezone format: {tz_offset_str}") | |
| sign, hours, minutes = match.groups() | |
| hours, minutes = int(hours), int(minutes) | |
| if sign == '-': | |
| hours, minutes = -hours, -minutes | |
| return timezone(timedelta(hours=hours, minutes=minutes)) |