PlayMaker Feedback > Action Requests

Date actions: day of the week, month length...

(1/3) > >>

szomaza:
Hi,

Some more DATE actions would be very handy for us non programmer types.

With Get System Date Time: https://hutonggames.fogbugz.com/default.asp?W823
we can already get the year, month and day. That is great!

An action to calculate the length of any particular month would be nice to have. (give year and month, get number of days in month)
Also an action to tell which weekday any particular year/month/day is.

Thanks in advance,
szomaza

szomaza:
Look what I did!  :-)
I reverse engineered the Int Add action to get familiar with stuff, then looked up a date function (DateTime.DaysInMonth Method (Int32, Int32)) and could solve my first problem with my very first PlayMaker action: YAY!


--- Code: ---// https://msdn.microsoft.com/en-us/library/system.datetime.daysinmonth(v=vs.110).aspx
// ArgumentOutOfRangeException
// month is less than 1 or greater than 12.
// -or-
// year is less than 1 or greater than 9999.

using UnityEngine;
using System;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Time)]
    [Tooltip("Returns the number of days in the specified year and month.")]
    public class GetNumberOfDaysInMonth : FsmStateAction
    {
        [RequiredField]
        public FsmInt year;
        [RequiredField]
        public FsmInt month;
        public FsmInt numberOfDays;

        public override void Reset()
        {
            year = null;
            month = null;
            numberOfDays = null;
        }

        public override void OnEnter()
        {
            numberOfDays.Value = DateTime.DaysInMonth(year.Value, month.Value);
        }
    }
}

--- End code ---

Now I'm off to do the research for the 2nd one: "which weekday any particular year/month/day is" .

Any improvements are appreciated. Like handling that exception when a higher number then 12 is entered for the month, etc to make it fool proof.
Also feel free to add "Copyright HutongGames" if you think this is useful, and please add it to the Ecosystem so I can easily find it at later times.

Thanks in advance:
szomaza

szomaza:
The 2nd one is done too.
Get day of week for specific year, month, day:


--- Code: ---// https://msdn.microsoft.com/en-us/library/bb762911%28v=vs.110%29.aspx

using UnityEngine;
using System;
using System.Globalization;
using System.Threading;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Time)]
    [Tooltip("Returns day of the week (Monday, Tuesday, ...) for the specified year, month, day.")]
    public class GetDayOfWeek : FsmStateAction
    {
        [RequiredField]
        public FsmInt year;
        [RequiredField]
        public FsmInt month;
        [RequiredField]
        public FsmInt day;

        public FsmString dayOfWeek;

        public override void Reset()
        {
            year = null;
            month = null;
            day = null;
            dayOfWeek = null;
        }

        public override void OnEnter()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            //DateTime dateValue = new DateTime(year.Value, month.Value, day.Value);
            //dayOfWeek.Value = dateValue.ToString("dddd", new CultureInfo("en-US"));

            DateTime dateValue = new DateTime(year.Value, month.Value, day.Value);
            dayOfWeek.Value = dateValue.ToString("dddd");
           
            Thread.CurrentThread.CurrentCulture = originalCulture;
        }
    }
}

--- End code ---

szomaza:
Looks like this:

szomaza:
These will work for me now, but I would really appreciate if somebody who knows what he/she is doing would "patch these up", handling exceptions, whatever... to make them "fool proof" and add them to the Ecosystem, so later it is easier to find.

Thanks in advance,
szomaza

Navigation

[0] Message Index

[#] Next page

Go to full version