It is currently April 23rd, 2024, 7:13 am

is it a leap year?

Tips and Tricks from the Rainmeter Community
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

is it a leap year?

Post by moshi »

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.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: is it a leap year?

Post by ikarus1969 »

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