AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Feature requests for future versions of Hollywood can be voiced here
Post Reply
Bugala
Posts: 1040
Joined: Sun Feb 14, 2010 7:11 pm

AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Post by Bugala »

Hollywoods own Time system is quite handy that you have these MakeDate() and ParseDate().

However, there is one oversight still. For example right Now I am using this Date as the tables ID:

table[date1]
table[date2]...

Difficulty is that when I want to go through this list in some sort of FOR-NEXT kind of loop, it is difficult to find out the next date.

It is easy if it happens to be like:
01-01-2001, since in that case it is simply day=day+1.

But what if date is 30, and I do +1, now I have to figure out which month it is to see if month should change or not, or even worse, if day is 28 and it is February, then I have to even figure out what year it is.

It is not anything that would be undoable, but it would be handy if there would be some command already in Hollywood where I could do something like:

Code: Select all

NewDate = AddTimeToDate(date1, #DAY, 45)
And this way 45 days would be added to the date1, and its result would be returned.

Flinx
Posts: 50
Joined: Sun Feb 14, 2021 9:54 am

Re: AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Post by Flinx »

Hi Bugala,

You can do this with the timestamp functions. In my example I have used your desired syntax, otherwise the function would have been shorter.

Code: Select all

Const #DAY=1

Function p_AddTimeToDate(d$,size,offset)
	Local stamp=DateToTimestamp(d$)

	Switch size
	Case #DAY
		offset=offset*3600*24
	EndSwitch

	Return(TimestampToDate(stamp+offset, True))
EndFunction

date1="10-Dec-2021 12:00:00"
NewDate = p_AddTimeToDate(date1, #DAY, 45)
DebugPrint(NewDate)

Flinx
Posts: 50
Joined: Sun Feb 14, 2021 9:54 am

Re: AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Post by Flinx »

Short version:

Code: Select all

d$="10-Dec-2021 12:00:00"
DebugPrint(TimestampToDate(DateToTimestamp(d$)+45*86400, True))

Bugala
Posts: 1040
Joined: Sun Feb 14, 2010 7:11 pm

Re: AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Post by Bugala »

Ah, thanks. Had missed that TimeStamp thing completely. That is handy.

Flinx
Posts: 50
Joined: Sun Feb 14, 2021 9:54 am

Re: AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Post by Flinx »

To make it perfect we still have to correct the UTC difference:

Code: Select all

d$="10-Dec-2021 12:00:00"
DebugPrint(TimestampToDate(DateToTimestamp(UTCToDate(d$))+42*86400, True))

Post Reply