It is currently April 23rd, 2024, 7:13 am
Tips and Tricks from the Rainmeter Community
moshi
Posts: 1740 Joined: November 13th, 2012, 9:53 pm
Post
by moshi » March 28th, 2014, 11:48 am
Microsoft's PowerShell can tell you whether a year is a leap year or not:
[DateTime]::IsLeapYear(2014)
will return "False"
while
[DateTime]::IsLeapYear(2012)
will return "True"
even exceptions like
[DateTime]::IsLeapYear(1900)
work fine. returns "False", as it should
this could be useful for calendars etc.
so how about using PowerShell with the RunCommand plugin:
http://rainmeter.net/forum/viewtopic.php?f=18&t=16715
Code: Select all
[Rainmeter]
OnRefreshAction=[!CommandMeasure Command_1 Run]
OnWakeAction=[!CommandMeasure Command_1 Run]
[MeasureCurrentYear]
Measure=Time
Format=%Y
OnChangeAction=[!CommandMeasure Command_1 Run]
[Command_1]
Measure=Plugin
Plugin=RunCommand
Parameter="echo | powershell.exe [DateTime]::IsLeapYear([MeasureCurrentYear])"
OutputType=ANSI
DynamicVariables=1
RegExpSubstitute=1
Substitute="True":"1","False":"0","\n":""
be careful not to have a section called
[DateTime] in your skin.
ikarus1969
Posts: 571 Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria
Post
by ikarus1969 » March 29th, 2014, 5:17 pm
thanks to moshi i now know a third way to know if a year is a leap-year.
i was using the following two until now:
for the LUA-lovers:
Code: Select all
function IsLeapYear(parm_year)
local myRet = false;
if (parm_year % 4 == 0) and (parm_year % 100 ~= 0) or (parm_year % 400 == 0) then
myRet = true;
else
myRet = false;
end
return myRet;
end
for the rainmeter-purists:
Code: Select all
[MeasureCurrentYear]
Measure=Time
Format=%Y
[Measure_LeapYear]
Measure=CALC
Formula=(((MeasureCurrentYear%4 = 0) && (MeasureCurrentYear%100 <> 0)) !! MeasureCurrentYear%400 = 0) ? 1 : 0