PDA

View Full Version : Free Date Difference Action Plugin


Worm
08-30-2005, 07:57 PM
After reading the post in beta forum, I thought I'd give this a whirl.

This plugin is called DateDiff and will let you easily add or subtract days, months, or years to/from a date.

Take it while ya can...

Unzip the DateDiff.zip and copy it to your Plugins\Actions
folder then fire up the sample app.

So for AMS it would be something like this:
C:\Program Files\AutoPlay Media Studio 5.0 Professional\Plugins\Actions\DateDiff

Be gentle now, this is my first real go at a true action plugin.

Intrigued
08-30-2005, 11:03 PM
Very useful Worm and thanks.

Seems to work properly right from the get go.

:yes

Worm
08-31-2005, 08:39 AM
Here's an updated version.

Added:
DateDiff.GetDayOfWeek
returns a numeric value representing the day the date passed falls on
(Sunday = 1 ... Saturday = 7)

DateDiff.GetDifference
returns the number of days between two dates.

Unzip and copy over the existing plugin files.

TJ_Tigger
08-31-2005, 08:48 AM
Another great addition to WormWare :D

csd214
08-31-2005, 08:54 AM
DateDiff.GetDayOfWeek
returns a numeric value representing the day the date passed falls on
(Sunday = 1 ... Saturday = 7)
Worm, I can’t resist to tease you:

Sunday isn’t the first day in the week in all counties. In Norway it is the 7th day!

Thanks for all your gifts. Have a nice day.

Worm
08-31-2005, 09:18 AM
Well...

I actually was thinking a little about that. That's why I returned a numeric rather than a string. I was going to return "Monday", "Tuesday", etc.. but thought if I returned a numeric, the user could create a table with their own strings for different languages. The date format being US (MM/DD/YYYY) I'm kind of stuck with as the C++ class I'm using only excepts the date in US format.

This is a test plugin for me. I'm trying to take some of the knowledge I gleaned from Brett when working on the DataGrid and put it to use. If there is a way to make this better, please say so, and I'll see what I can do.

Worm
08-31-2005, 09:34 AM
Another update:

Added:
DateDiff.FormatSeconds

takes the number of seconds passed, and formats it into a string HH:MM:SS

dthompson16
08-31-2005, 10:06 AM
Good going, Worm. What I had in mind was a duplicate of the DateDiff function in VB. The syntax for which is in attached .png.

dthompson16
08-31-2005, 10:29 AM
BTW, Worm, since you have modified your date difference plugin a couple of times, do you happen to have full documentation for it that I can keep in one place handy for reference? Thanks. Glad to see someone out there eats code that is breakfast of champions, ditto Tigg. :) Even Excel spreadsheets have this function, so it will be great to have something similar for Six.

Worm
08-31-2005, 10:30 AM
The help file should be up to date with the latest additiions.

csd214
08-31-2005, 11:07 AM
the user could create a table with their own strings for different languages

YES; no problem! (… and you have an example in your help file). I was joking; tried to.

BTW I had to do the same “adjustment” when working with a language delivered by a well known vendor (with address Redmond)).

It’s really nice to have these commands integrated in AMS. LuaCom has some helpful functions for local date formats.

t = os.date('*t') -- time now [table elements hour, min, wday, year, yday, month, sec, day]
-- some adjustments needed because the result is displayed in an object with input mask ##/##/####
if String.Length(t.day) == 1 then
t.day = "0"..t.day;
end
if String.Length(t.month) == 1 then
t.month = "0"..t.month;
end
Input.SetText("inpLocaleDate", t.day.."."..t.month.."."..t.year);

Worm
08-31-2005, 12:13 PM
I knew you were jabbing me a little csd214. :)

But to be honest when it comes to international dates, you're absolutely right, I'm clueless. :eek:

dthompson16
08-31-2005, 12:25 PM
Yes, thank you, I printed out your help file. Nice. One final question: what will DateDiff.GetDifference do if I attempt to enter a date that's not on the calendar like Feb 29, 1999 or Aug 33, 2005?

Worm
08-31-2005, 01:16 PM
In a perfect world it should return -1 for an invalid date format, but I just tried it and it gave me a result.

I'll look into it when I get a chance.

dthompson16
09-01-2005, 08:59 AM
10-4. Thanks again. I'll stay tuned in.

Worm
09-01-2005, 09:02 AM
I've squashed that bug, but am having some problems getting AMS to read my XML file for the intellisense. Once I get that figured out, I'll upload the latest rev.

I've also added a couple more functions

IsEqual
IsGreaterThan
IsLessThan
IsValid

Worm
09-01-2005, 09:56 AM
Here it is... fixed the bug and added a couple more functions. Check the help for info.

csd214
09-01-2005, 10:18 AM
I tried to use LuaCom to adjust the date format, but I don’t feel familiar with the plugin. I found it easier to just read the Registry On Preload

sShortDate = Registry.GetValue(HKEY_CURRENT_USER, "Control Panel\\International", "sShortDate", true);
bEuroFormat = false;
if String.CompareNoCase(String.Left(sShortDate, 2), "dd") == 0 then
-- equal; = European format
bEuroFormat = true;
end
sDateSep = Registry.GetValue(HKEY_CURRENT_USER, "Control Panel\\International", "sDate", true);

I added a global function
function DateConv(sValue)
if bEuroFormat then
return String.Mid(sValue, 4, 2)..sDateSep..String.Left(sValue, 2)..sDateSep..String.Right(sValue, 4);
else
return sValue;
end
end

and changed the sDate and sNewDate actions
sDate = DateConv(Input.GetText("txtDate"));
sNewDate = DateConv(DateDiff.AddDays(sDate, nDays));

Worm, now you plugin loves LUTEFISK and LEFSE.

Worm
09-01-2005, 10:26 AM
Thanks for the helper functions!

dthompson16
09-01-2005, 01:39 PM
I downloaded DateDiff.zip and unzipped the contents to C:\Program Files\AutoPlay Media Studio Professional 6.0\Plugins\Actions. I then worked up a small test project and put a starting date & ending date & a line nDays = DateDiff.GetDifference etc. into Global Functions. When I previewed the project I got an error msg: Globals, Line 3: Attempt to index global 'DateDiff' (a nil value). What am I doing wrong? Thanks.

Worm
09-01-2005, 01:45 PM
Don't forget to enable the plugin in the menu system

Go to Project-->Plugins--> Then tick the DateDiff box

dthompson16
09-01-2005, 02:15 PM
Works great! Bravo!

Worm
09-01-2005, 02:40 PM
Thanks!

I did look into the DateDiff thing a little, but time isn't on my side to do to much hunting. I haven't yet come across a solution to add to the plugin, but did see that VBScript supports this, so you could use a web objecty to get the info.


Here's a little example I put together that shows a way to use VBScript Code in your project using a web object. It could also be done with luaCom.

dthompson16
09-01-2005, 05:28 PM
I think it's still usable. By the way, do you happen to know what range of years it accepts? I'm assuming it's 1 AD to 3999 AD.

Worm
09-28-2005, 06:44 PM
Whoaa!

Answered a question, I already answered. I really need to get some sleep

:eek: :eek: :eek:

azmanar
01-05-2006, 12:23 AM
Here's an updated version.

Added:
DateDiff.GetDayOfWeek
returns a numeric value representing the day the date passed falls on
(Sunday = 1 ... Saturday = 7)

DateDiff.GetDifference
returns the number of days between two dates.

Unzip and copy over the existing plugin files.

Hi,

I can't find the updated ATTACHMENT.

azmanar
01-05-2006, 02:31 AM
Hi,

I can't find the updated ATTACHMENT.


Ok. Found it.

Thanx

Worm
01-05-2006, 05:57 AM
Glad I could help :o