Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/cristhianblaffita-web/Weather-App-Ts/llms.txt

Use this file to discover all available pages before exploring further.

Weather App TS ships four pure utility functions — formatDate, isDayTime, getCloudCoverage, and getWeatherIcon — that handle all data transformation logic outside of components and hooks. Keeping this logic in standalone modules makes each function independently testable, prevents business rules from leaking into JSX, and lets components stay focused on rendering. None of these functions produce side effects or depend on React state.

formatDate(isoDate)

formatDate takes an ISO 8601 datetime string (as returned by the Open-Meteo API) and produces three pre-formatted string representations suited to different parts of the UI. Signature
function formatDate(isoDate: string): {
  fullDate: string;
  shortDate: string;
  hourOnly: string | undefined;
}
The function splits the input on "T" to separate the date and time portions, constructs a Date object from the date part, and formats it via Intl.DateTimeFormat with the en-US locale. The time portion is sliced to extract the HH:MM segment directly from the original string, so no timezone conversion is applied to the hour value. Given the input "2024-07-15T14:30", the return value is:
FieldExample Output
fullDate"Jul 15, 2024"
shortDate"Mon, Jul 15"
hourOnly"14:30"
fullDate is formatted with { month: 'short', day: 'numeric', year: 'numeric' } and is used wherever a complete, unambiguous date is needed. shortDate uses { weekday: 'short', month: 'short', day: 'numeric' } and appears in the daily forecast cards. hourOnly is used for hourly forecast labels.

isDayTime(currentDate, sunriseList, sunsetList)

isDayTime determines whether a given datetime falls between sunrise and sunset on the same calendar day, using the daily sunrise and sunset arrays from the Open-Meteo forecast response. Signature
function isDayTime(
  currentDate: string,
  sunriseList: string[],
  sunsetList: string[]
): boolean
The function locates the correct entry in sunriseList by comparing the first ten characters of each element (YYYY-MM-DD) against the first ten characters of currentDate. Once the index is found, it extracts the HH:MM portion (characters 11–15) from currentDate, the matching sunrise entry, and the matching sunset entry. It then performs a string-lexicographic comparison — valid for zero-padded 24-hour time strings — and returns true if the current hour falls within [sunriseHour, sunsetHour). The function returns false if the date cannot be found in the sunrise list.
const isDay = isDayTime(
  "2024-07-15T14:30",
  ["2024-07-15T05:12"],  // sunrise
  ["2024-07-15T21:08"]   // sunset
);
// returns true

getCloudCoverage(cloudCover)

getCloudCoverage maps a numeric cloud cover percentage (as returned in the cloud_cover field of the Open-Meteo current weather block) to a human-readable description. Signature
function getCloudCoverage(cloudCover: number): string
The function applies a series of threshold checks and returns one of four fixed string labels:
cloudCover RangeReturn Value
0 – 20"Clear"
21 – 50"Partly Cloudy"
51 – 80"Mostly Cloudy"
81 – 100"Overcast"

getWeatherIcon(code, isDay) and weatherCodes

getWeatherIcon resolves a WMO weather interpretation code to a Lucide React icon component and a text label, with day/night variants for clear and partly-cloudy conditions. Signature
function getWeatherIcon(
  code: number,
  isDay: boolean
): { icon: LucideIcon; label: string }
The function looks up code in the weatherCodes record. If isDay is true, it returns the entry’s icon property (the daytime icon). If isDay is false, it returns iconNight when available, falling back to the daytime icon for codes that have no distinct night variant. If code is not present in the record at all, the function falls back to the Overcast entry (code 3) to ensure a valid icon is always returned. The full set of supported WMO codes and their night-icon availability is:
CodeLabelHas Night Icon
0Clear sky✓ (Moon)
1Mainly clear✓ (CloudMoon)
2Partly cloudy✓ (CloudMoon)
3Overcast
45Fog
48Depositing rime fog
51Light drizzle
53Moderate drizzle
55Dense drizzle
56Light freezing drizzle
57Dense freezing drizzle
61Slight rain
63Moderate rain
65Heavy rain
66Freezing rain
67Heavy freezing rain
71Slight snow fall
73Moderate snow fall
75Heavy snow fall
77Snow grains
80Slight rain showers
81Moderate rain showers
82Violent rain showers
85Slight snow showers
86Heavy snow showers
95Thunderstorm
96Thunderstorm with slight hail
99Thunderstorm with heavy hail

Build docs developers (and LLMs) love