playMaker

Author Topic: Leap Year  (Read 1722 times)

cmonroy

  • Playmaker Newbie
  • *
  • Posts: 34
Leap Year
« on: May 14, 2015, 02:48:52 AM »
I was looking for a way to detect if a given year is leap or not (along with some other useful date functions) but found none, so I tried to make a custom action:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Date")]
[Tooltip("Determines if a given year is leap or not")]

public class LeapYear : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Stores the year to test as an int")]
public FsmFloat yearToCheck;
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Shows if the year is leap as TRUE")]
public FsmBool isLeapYear;

public override void Reset()
{
yearToCheck = null;
isLeapYear = null;
}

public override void OnEnter()
{
if ((yearToCheck % 4 == 0) && !(yearToCheck % 100 == 0) || (yearToCheck % 400 == 0))
isLeapYear = true;
else
isLeapYear = false;
Finish ();
}
}
}

It seems, however, that the mod operator is not supported... Any ideas?

Thank you.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Leap Year
« Reply #1 on: May 14, 2015, 05:08:27 AM »
Hi,

 Instead simply use the c# build in function:

https://msdn.microsoft.com/en-us/library/system.datetime.isleapyear(v=vs.110).aspx

Bye,

 Jean