From 9acd1953acff9bfbb94f063dcc88fa8db03263eb Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 11 Mar 2025 15:43:54 +0000 Subject: [PATCH] feat: Update endpoint endpoint --- app/api/endpoints/endpoint.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/api/endpoints/endpoint.py b/app/api/endpoints/endpoint.py index e69de29..ece9251 100644 --- a/app/api/endpoints/endpoint.py +++ b/app/api/endpoints/endpoint.py @@ -0,0 +1,25 @@ +from typing import Optional +from fastapi import APIRouter, Depends, HTTPException +from pydantic import BaseModel +from datetime import datetime, timezone + +router = APIRouter() + +class TimezoneRequest(BaseModel): + timezone: str + +class TimezoneResponse(BaseModel): + current_time: str + +@router.post("/timezone", response_model=TimezoneResponse) +async def get_current_time(request: TimezoneRequest): + """ + Get the current time for a given timezone + """ + try: + tz = timezone(request.timezone) + except ValueError as e: + raise HTTPException(status_code=400, detail=str(e)) + + current_time = datetime.now(tz).isoformat() + return {"current_time": current_time} \ No newline at end of file