Skip to content

Commit

Permalink
feat: 현재 날짜 기준으로 기상정보 불러오기 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Db0111 committed Aug 20, 2024
1 parent 2296c8b commit 3bca903
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/service/weather.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { WeatherResponse } from '@/types/weather';

const date = new Date();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const year = date.getFullYear().toString();
const day = date.getDate().toString().padStart(2, '0');
const hour = date.getHours().toString().padStart(2, '0');
const minute = date.getMinutes().toString().padStart(2, '0');
const second = date.getSeconds().toString().padStart(2, '0');

const now = `${year}-${month}-${day}T${hour}:${minute}:${second}`;

export async function getWeather(): Promise<WeatherResponse> {
try {
const res = await fetch(
`${
import.meta.env.VITE_SERVER_URL
}/weather/forecast?now=2024-08-17T15:00:00&nx=60&ny=127`
}/weather/forecast?now=${now}&nx=60&ny=127`
);
const json = await res.json();

Expand Down

0 comments on commit 3bca903

Please sign in to comment.