playMaker

Author Topic: Leap Year  (Read 1064 times)

cmonroy

  • Playmaker Newbie
  • *
  • Posts: 34
    • View Profile
Leap Year
« on: May 13, 2015, 11:48:52 PM »
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: 14244
  • Official Playmaker Support
    • View Profile
Re: Leap Year
« Reply #1 on: May 14, 2015, 02: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