Skip to content

Commit 835d1ce

Browse files
authored
Update views_api.py
Add Timezone
1 parent 5b478b8 commit 835d1ce

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

views_api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from fastapi import Depends, HTTPException, Query, Request
44
from loguru import logger
55
import re
6+
import zoneinfo
67

78
from lnbits.core.crud import get_user, update_payment_extra
89
from lnbits.decorators import (
@@ -30,6 +31,9 @@
3031
async def api_list_currencies_available():
3132
return list(currencies.keys())
3233

34+
@devicetimer_ext.get("/api/v1/timezones")
35+
async def api_list_timezones_available():
36+
return sorted(zoneinfo.available_timezones(),key=str.lower)
3337

3438
@devicetimer_ext.post("/api/v1/device", dependencies=[Depends(require_admin_key)])
3539
async def api_lnurldevice_create(data: CreateLnurldevice, req: Request):
@@ -38,6 +42,11 @@ async def api_lnurldevice_create(data: CreateLnurldevice, req: Request):
3842
raise HTTPException(
3943
status_code=HTTPStatus.BAD_REQUEST, detail="Opening time format must be hh:mm"
4044
)
45+
46+
if data.timezone not in zoneinfo.available_timezones():
47+
raise HTTPException(
48+
status_code=HTTPStatus.BAD_REQUEST, detail="Illegal timezone"
49+
)
4150

4251
result = re.search("^\d{2}\:\d{2}$",data.available_stop)
4352
if not result:
@@ -64,6 +73,11 @@ async def api_lnurldevice_update(
6473
raise HTTPException(
6574
status_code=HTTPStatus.BAD_REQUEST, detail="Opening time format must be hh:mm"
6675
)
76+
77+
if data.timezone not in zoneinfo.available_timezones():
78+
raise HTTPException(
79+
status_code=HTTPStatus.BAD_REQUEST, detail="Illegal timezone"
80+
)
6781

6882
result = re.search("^\d{2}\:\d{2}$",data.available_stop)
6983
if not result:

0 commit comments

Comments
 (0)