Skip to content

Commit 44ce107

Browse files
committed
feat: Use yearless date comparison for season label in outfit recommendation dialog
1 parent 909f67a commit 44ce107

3 files changed

Lines changed: 54 additions & 8 deletions

File tree

src/components/dayMonthInput.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Created Date: 2026-03-20 22:08:57
66
* Author: 3urobeat
77
*
8-
* Last Modified: 2026-03-21 21:05:42
8+
* Last Modified: 2026-03-21 22:00:23
99
* Modified By: 3urobeat
1010
*
1111
* Copyright (c) 2026 3urobeat <https://github.com/3urobeat>
@@ -45,6 +45,8 @@
4545

4646

4747
<script setup lang="ts">
48+
import { YEARLESS_DATE_YEAR } from '~/utils/utils';
49+
4850
4951
// Define Props to be accepted by this component
5052
const props = defineProps({
@@ -68,23 +70,23 @@
6870
6971
if (props.modelValue != null) {
7072
date.value = new Date((props.modelValue as number));
71-
date.value.setUTCFullYear(2024); // Use a lap year so Feb 29 is always an option
73+
date.value.setUTCFullYear(YEARLESS_DATE_YEAR);
7274
daysInThisMonth.value = getDaysPerMonth(date.value.getMonth());
7375
}
7476
7577
7678
// Calculate days in the selected month
7779
function getDaysPerMonth(month: number): number {
7880
// Use a lap year so Feb 29 is always an option. Date(year, monthIndex + 1, 0) returns the last day of the current month
79-
return new Date(2024, month + 1, 0).getDate();
81+
return new Date(YEARLESS_DATE_YEAR, month + 1, 0).getDate();
8082
};
8183
8284
// Preprocess: Incoming value inits date, incoming null unsets date. Returns boolean indicating whether parent function should continue
8385
function setOrUnset(val: number | string | null): boolean {
8486
if (val != null && val != "") { // null option will be an empty string
8587
if (date.value == null) {
8688
date.value = new Date(0);
87-
date.value.setUTCFullYear(2024, 0, 1); // Use a lap year so Feb 29 is always an option
89+
date.value.setUTCFullYear(YEARLESS_DATE_YEAR, 0, 1);
8890
}
8991
return true;
9092
} else {

src/components/outfitRecommendationDialog.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Created Date: 2026-03-01 15:17:09
66
* Author: 3urobeat
77
*
8-
* Last Modified: 2026-03-15 19:40:01
8+
* Last Modified: 2026-03-21 23:28:57
99
* Modified By: 3urobeat
1010
*
1111
* Copyright (c) 2026 3urobeat <https://github.com/3urobeat>
@@ -130,8 +130,12 @@
130130
131131
let matchesWeather = (!weatherAPIErrorMessage && value.fromTemp! <= currentWeather?.main.temp! && value.toTemp! >= currentWeather?.main.temp!); // TODO: Only looks at current temp, not at day forecast
132132
133-
// TODO: Remove year from timestamp!
134-
let matchesDate = (value.fromTimestamp! <= Date.now() && value.toTimestamp! >= Date.now());
133+
let matchesDate;
134+
if (value.fromTimestamp != null && value.toTimestamp != null) {
135+
matchesDate = isNowBetweenDatesIgnoringYear(value.fromTimestamp!, value.toTimestamp!);
136+
}
137+
138+
console.debug(`[DEBUG] getOutfitsToShowInPopout:`, e.name, (value.fromTemp != null && value.toTemp != null), (value.fromTimestamp != null && value.toTimestamp != null), matchesWeather, matchesDate);
135139
136140
// Temperature AND Weather constraint set?
137141
if (value.fromTemp != null && value.toTemp != null && value.fromTimestamp != null && value.toTimestamp != null) {

src/utils/utils.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created Date: 2026-01-23 22:00:18
55
* Author: 3urobeat
66
*
7-
* Last Modified: 2026-03-15 19:56:39
7+
* Last Modified: 2026-03-21 23:25:50
88
* Modified By: 3urobeat
99
*
1010
* Copyright (c) 2026 3urobeat <https://github.com/3urobeat>
@@ -175,3 +175,43 @@ export function formatTime(time: number) {
175175

176176
return `${Math.round(until)} ${untilUnit}`;
177177
}
178+
179+
180+
// Year used for dates where year is being ignored (I swear this makes sense)
181+
export const YEARLESS_DATE_YEAR = 2024; // Use a lap year so Feb 29 is always an option
182+
183+
/**
184+
* Inits a yearless and timeless date object from a timestamp
185+
* @param timestamp Optional: Timestamp to parse. If undefined, current time is used
186+
* @returns Returns constructed Date object
187+
*/
188+
export function initYearlessDate(timestamp?: number): Date {
189+
const date = timestamp != undefined ? new Date(timestamp) : new Date();
190+
191+
date.setUTCFullYear(YEARLESS_DATE_YEAR);
192+
date.setUTCHours(0, 0, 0, 0); // Intentionally not using UTC here to remove timezone
193+
194+
return date;
195+
}
196+
197+
/**
198+
* Is current timestamp between (<= & >=) from & to while ignoring year?
199+
* @param from From: If greater than to, the previous year will be used internally
200+
* @param to ...
201+
* @returns Boolean indicating whether now is between from & to
202+
*/
203+
export function isNowBetweenDatesIgnoringYear(from: number, to: number): boolean {
204+
205+
// Parse dates and bring them all onto the same year to effectively ignore it
206+
const fromDate = initYearlessDate(from);
207+
const toDate = initYearlessDate(to);
208+
const nowDate = initYearlessDate();
209+
210+
// Handle special case where from > to
211+
fromDate.setUTCFullYear(YEARLESS_DATE_YEAR - (from > to ? 1 : 0));
212+
213+
// console.debug("[DEBUG] isNowBetweenDatesIgnoringYear: ", fromDate, toDate, nowDate);
214+
215+
return (fromDate.getTime() <= nowDate.getTime()) && (toDate.getTime() >= nowDate.getTime());
216+
217+
}

0 commit comments

Comments
 (0)