playMaker

Author Topic: AddToDate action please[SOLVED]  (Read 2619 times)

szomaza

  • Sr. Member
  • ****
  • Posts: 253
AddToDate action please[SOLVED]
« on: June 22, 2019, 09:38:51 AM »
Hi,

There are a few great actions for dealing with Date and Time which I use, like:
GetSystemDateTime
GetTimeSpanBetweenDates
ConvertSecondsToString

but I don't seem to find any AddToDate action.
It would be great if it could operate on the same format which you can specify in the other actions. I use: MM/dd/yyyy HH:mm:ss
Could specify the time to add in float seconds (or even better to choose between days, hours, minutes) and it would simply return the new date in the same string format.

I searched here in the forum and on the Ecosystem but could not find anything like this.

Thanks in advance,
szomaza
« Last Edit: July 10, 2019, 09:37:59 AM by jeanfabre »

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: AddToDate action please
« Reply #1 on: June 29, 2019, 10:08:57 AM »
OK I almost managed to figure out how to do this by combining from the IntAdd and GetTimeSpanBetweenDates and searching the net.  :)

It works when I put a specific number to the code line which adds to the date, but when I replace the number with the integer variable then it gives me this error:

Assets/PlayMaker/Actions/Time/AddToDateTime.cs(41,69): error CS1503: Argument `#1' cannot convert `HutongGames.PlayMaker.FsmInt' expression to type `double'

Please check the code, and help me out with this bit.
You could also put it right to Ecosystem if you manage to get it working with the int variable.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using System;
using System.Globalization;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Time)]
[Tooltip("Adds seconds to date and time and stores it in a string variable. An optional format string gives you a lot of control over the formatting (see online docs for format syntax).")]
public class AddToDateTime : FsmStateAction
{
        [RequiredField]
        [Tooltip("The time and date to add seconds to.")]
        [UIHint(UIHint.FsmString)]
        public FsmString startDate;

        [RequiredField]
        [Tooltip("Integer seconds to add to date.")]
        [UIHint(UIHint.Variable)]
        public FsmInt add;

        [UIHint(UIHint.Variable)]
[Tooltip("Store result date and time as a string.")]
public FsmString storeString;

        [Tooltip("Optional format string. E.g., MM/dd/yyyy HH:mm:ss")]
        public FsmString dateFormat;

public override void Reset()
{
            startDate = null;
            storeString = null;
            dateFormat = "MM/dd/yyyy HH:mm:ss";
            add = null;
}

public override void OnEnter()
{
            CultureInfo provider = CultureInfo.InvariantCulture;
            DateTime _startDate = DateTime.ParseExact(startDate.Value, dateFormat.Value, provider);

            //this works
            _startDate = _startDate.Add(System.TimeSpan.FromSeconds(100));       


            //but if I try to add the int variable like so
//            _startDate = _startDate.Add(System.TimeSpan.FromSeconds(add));

            // then it gives an error:
            //  Assets / PlayMaker / Actions / Time / AddToDateTime.cs(41, 69): error CS1503: Argument `#1' cannot convert `HutongGames.PlayMaker.FsmInt' expression to type `double'
            // how do I fix this?

            storeString.Value = _startDate.ToString(dateFormat.Value);
      }

#if UNITY_EDITOR
    public override string AutoName()
    {
            return ActionHelpers.AutoName(this, startDate, add, storeString, dateFormat);
    }
#endif

}
}

Thanks in advance,
szomaza


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: AddToDate action please
« Reply #2 on: July 04, 2019, 04:29:48 AM »
Hi,

yes, cool, fixed it.

 basically, you need to get the value of the fsmInt Add propery and convert it to int like so:

Quote
_startDate = _startDate.Add(System.TimeSpan.FromSeconds((int)add.Value));

I have put it on the ecosystem. Let me know if it works. I reworked the layout and definition of properties for more clarity.



Let me know how it goes for you, and I'll tweet about it then.

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: AddToDate action please
« Reply #3 on: July 04, 2019, 04:31:02 AM »
Hi,

 but maybe I should go the extra mile and give a date format for the add property so that you can add more then just seconds? you then can add any time with a specific date format independly from the base date time format.

 Bye.

 Jean

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: AddToDate action please
« Reply #4 on: July 07, 2019, 04:47:55 AM »
Thank you Jean for fixing/improving it and also for the explanation!

I can't seem to find it on the Ecosystem from Unity and also not seeing it here:
https://github.com/PlayMakerEcosystem/PlayMakerCustomActions_U5/tree/master/Assets/PlayMaker%20Custom%20Actions/Time

It should be there, right?

br,
szomaza

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: AddToDate action please
« Reply #5 on: July 08, 2019, 08:16:58 AM »
Hi,

 yeah.. sorry forgot to push the changes :) now it's up

Bye,

 Jean

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: AddToDate action please
« Reply #6 on: July 08, 2019, 11:39:49 AM »
OK now I could find it from Github, but still not from the Ecosystem.

The action works, adds the seconds nicely but the state with it does not finish.
It's only missing this line from the end:
Finish();

You could also remove my comments from it:
https://github.com/PlayMakerEcosystem/PlayMakerCustomActions_U5/blob/master/Assets/PlayMaker%20Custom%20Actions/Time/AddToDateTime.cs

Thanks a lot!
szomaza
« Last Edit: July 08, 2019, 11:47:08 AM by szomaza »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: AddToDate action please
« Reply #7 on: July 08, 2019, 12:26:52 PM »
Hi,

 Cool, fixed it. I realized it was also not ready for ecosystem search, now it will be listed.

 Bye.

 Jean

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: AddToDate action please
« Reply #8 on: July 08, 2019, 12:57:43 PM »
Thanks, everything works perfectly!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: AddToDate action please[SOLVED]
« Reply #9 on: July 10, 2019, 09:38:14 AM »
Hi,

 Perfect!

 Bye,

 Jean