← Pixel Dreamer Studio

Turn a day counter into season, day and year without a day 0

Subtract 1 before dividing, then add 1 back to the day of the season.

Farming and life game calendars count from day 1, but dividing by 28 counts from 0. In our Godot 4.7 test of 4 seasons of 28 days, day / 28 made Spring 27 days long, called day 28 Summer day 0, and on day 112, the last day of Winter, gave index 4, one past the 4 seasons, and year 2. Subtracting 1 first gave every season 28 days, numbered 1 to 28.

The code

Keep one day counter that starts at 1 and goes up each morning, and save only that. Ask the script for season_index(day), day_of_season(day) and year(day) when you need them.

extends Node
## Season, day of the season and year from a day counter that starts at 1,
## like most farming and life game calendars: 4 seasons of 28 days.

const DAYS_PER_SEASON := 28
const SEASONS := ["Spring", "Summer", "Fall", "Winter"]


static func season_index(day: int) -> int:
	return ((day - 1) / DAYS_PER_SEASON) % SEASONS.size()


static func day_of_season(day: int) -> int:
	return (day - 1) % DAYS_PER_SEASON + 1


static func year(day: int) -> int:
	return (day - 1) / (DAYS_PER_SEASON * SEASONS.size()) + 1

What we measured

Every day of the first year, and the days around season and year ends. Two runs with the same numbers.

Why it happens

Integer division puts 0 to 27 in the first group. A counter that starts at 1 has only 27 of those days in Spring and pushes day 28 into the next group. Doing the math on day - 1 lines the groups up again, and + 1 gives the day back its human number.

What to change

Effects only at night, even across midnight: night-only effects.

Ready-made cozy effects: Cozy VFX for Godot 4 has 29 ready-made effects for farming and life games, including fireflies, sleeping Zzz, hearts, music notes, steam and falling leaves.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Cozy VFX for Godot 4 has 29 ready-made effects for farming and life games, including fireflies, sleeping Zzz, hearts, music notes, steam and falling leaves.

More how-tos for Cozy VFX for Godot 4: Night-only effects when the night crosses midnight

More how-tos: Game systems