It is currently March 28th, 2024, 3:52 pm
Days in a Year
-
- Posts: 2
- Joined: December 19th, 2016, 7:57 am
Days in a Year
Can someone here teach me how to calculate the days in a year. For example 365 days in a year and 366 in leap year.
- jsmorley
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Days in a Year
There are some complicated formulas out there for calculating leap years and all that, but I'm not sure how best to implement them in native Rainmeter. It could be done in Lua without too much trouble, but it can also be done without complicated formulas using 3 measures in Rainmeter:
I'm not sure what context you want to use this in, and if you are looking to design a full-blown calendar in Rainmeter, I would suggest jumping to Lua, it has been done before. https://smurfier.deviantart.com/art/LuaCalendar-6-0-280738925
The calculation is:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
Year=2020
[MeasureStart]
Measure=Time
TimeStamp=Jan 1 #Year# 00:00:00 AM
TimeStampFormat=%b %#d %Y %I:%M:%S %p
Format=%A, %B %#d, %Y at %H:%M:%S %p
[MeasureEnd]
Measure=Time
TimeStamp=Dec 31 #Year# 12:59:59 PM
TimeStampFormat=%b %#d %Y %I:%M:%S %p
Format=%A, %B %#d, %Y at %H:%M:%S %p
[MeasureDays]
Measure=Calc
Formula=Round(([MeasureEnd:Timestamp] - [MeasureStart:Timestamp])/86400)
DynamicVariables=1
[MeterDays]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=There are [MeasureDays] days in the year #Year##CRLF##CRLF#From#CRLF#[MeasureStart]#CRLF#To#CRLF#[MeasureEnd]
The calculation is:
Days in a year calculation
Gregorian calendar year
One calendar common year has 365 days:
1 common year = 365 days
One calendar leap year has 366 days:
1 leap year = 366 days
Leap year occurs every year that is evenly divisible by 4, except for years that are not evenly divisible by 100 or evenly divisible by 400.
- jsmorley
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Days in a Year
Actually, in looking at it, the formula in Rainmeter isn't all that hard...
So again, it's a leap year if the year is evenly divisible by 4 AND the year is not evenly divisible by 100 OR is evenly divisible by 400.
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
Year=2020
[MeasureLeap]
Measure=Calc
IfCondition=(#Year#%4 = 0) && ((#Year#%100 <> 0) || (#Year#%400 = 0))
IfTrueAction=[!SetOption MeterDays Text "There are 366 days in the year #Year#, a leap year"]
IfFalseAction=[!SetOption MeterDays Text "There are 365 days in the year #Year#, not a leap year"]
[MeterDays]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
- jsmorley
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Days in a Year
But I'd still be tempted to make it a simple callable function in Lua:
Skin:
Lua:
Skin:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Lua]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1
[Meter2020]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=There are [&Lua:DaysInYear(2020)] days in 2020
DynamicVariables=1
[Meter2021]
Meter=String
Y=5R
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=There are [&Lua:DaysInYear(2021)] days in 2021
DynamicVariables=1
Code: Select all
function DaysInYear(yearArg)
if yearArg%4==0 and (yearArg%100~=0 or yearArg%400==0) then
return 366
else
return 365
end
end