Days in a Year
Posted: December 9th, 2017, 5:19 pm
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.
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]
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.
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
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