Spaces:
Runtime error
Runtime error
Update src/utils/time_utils.py
Browse files- src/utils/time_utils.py +37 -15
src/utils/time_utils.py
CHANGED
|
@@ -1,19 +1,41 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
-
STATUS_COLORS = {
|
| 6 |
-
"free": "#ffffff",
|
| 7 |
-
"occupied": "#8e44ad",
|
| 8 |
-
"need_cleaning": "#e74c3c",
|
| 9 |
-
"out_of_service": "#95a5a6",
|
| 10 |
-
}
|
| 11 |
|
| 12 |
-
|
| 13 |
-
"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
"
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime, timedelta
|
| 2 |
+
import pytz
|
| 3 |
|
| 4 |
+
# Hotel timezone
|
| 5 |
+
OMAN_TZ = pytz.timezone("Asia/Muscat")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def utc_now_iso() -> str:
|
| 9 |
+
"""
|
| 10 |
+
Returns current UTC time in ISO-8601 format.
|
| 11 |
+
Used for all audit-safe timestamps.
|
| 12 |
+
"""
|
| 13 |
+
return datetime.utcnow().replace(microsecond=0).isoformat() + "Z"
|
| 14 |
|
| 15 |
+
|
| 16 |
+
def local_now() -> datetime:
|
| 17 |
+
"""
|
| 18 |
+
Returns current local time in Asia/Muscat timezone.
|
| 19 |
+
"""
|
| 20 |
+
return datetime.now(OMAN_TZ)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def local_date_str() -> str:
|
| 24 |
+
"""
|
| 25 |
+
Returns local date (Asia/Muscat) as YYYY-MM-DD.
|
| 26 |
+
"""
|
| 27 |
+
return local_now().strftime("%Y-%m-%d")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def business_date_for_closing(now: datetime | None = None) -> str:
|
| 31 |
+
"""
|
| 32 |
+
Business day closes at 06:00 Asia/Muscat.
|
| 33 |
+
- Before 06:00 → business day = yesterday
|
| 34 |
+
- After 06:00 → business day = today
|
| 35 |
+
"""
|
| 36 |
+
if now is None:
|
| 37 |
+
now = local_now()
|
| 38 |
+
|
| 39 |
+
if now.hour < 6:
|
| 40 |
+
return (now.date() - timedelta(days=1)).isoformat()
|
| 41 |
+
return now.date().isoformat()
|