Date Commmands

BlitzMax Forums/BlitzMax Programming/Date Commmands

Blitzer101(Posted 2006) [#1]
Hi,

I'm currently writing some code (some of you may have seen me ramble elsewhere about it) to provide more functions to works with dates other than just CurrentDate$ or manipulating dates yourself.

Firstly, what I'd really like to know ATM is how much interest there would be in me eventually making this into a module? - It's my intention is for it to be complete free.

Secondly are there any functions that you think I should include (if I can do it!) or any ideas you have as in to how it will work?

I have the following so far (copied from another thread)...


All parameters in <> are optional.
If "datestring" is omitted then the system date is used.
If DD, MM and YYYY (where applicable) are all omited then the system date will be used.
Where appropriate leap years are tested/allowed for.


year% = date.Year(<"string">) ' returns year as a number from "string" - Used internally to get value from CurrentDate$

month% = date.Month(<"string">) ' returns month as a number from "string" - Used internally to get value from CurrentDate$

date% = date.Date(<"string">) ' returns day number of month as a number from "string" - Used internally to get value from CurrentDate$

lengthofmonth% = date.DaysPerMonth(<MM,YYYY>) ' returns number of days for month MM in year YYYY.

leapyear% = date.IsLeapYear(<YYYY>) ' returns True/False if year YYYY is leapyear or not.

dayofyear% = date.DayOfYear(<DD,MM,YYYY>) ' returns number of day in year starting at 1 for Jan 1st.

daystoyearend% = date.DaysToYearEnd(<DD,MM,YYYY>) ' returns number of days from date provided until end of that same year.

daycount% = date.DayCount(<DD,MM,YYYY>) ' returns a count of days using the Gregorian calender exclusively. Count starts with day 1 being 1-1-0001

daysbetween% = date.DaysBetween(fromDD, fromMM, fromYYYY, ToDD, ToMM, ToYYYY) ' returns count of days between two dates. I'm liable to drop this method as it's just as simple to use DayCount(<1st Date>)-DayCount(<2nd Date>)

dayname$ = date.DayName(<DD, MM, YYYY, True/False>) ' returns day name (mon, tues) etc. from date given. Optional parameter (True) returns long day name e.g. Monday. Default (False) returns short day name e.g. Mon


Also planned...

weeknum% = date.WeekNumber(<DD, MM, YYYY, OFFSET>) ' returns week number 1-52 for given date. Not decided whether or not to bother with the OFFSET parameter yet - might be over-kill. This is currently in progess and going slow - but I'm getting there. :)

datestring$ = date.Format(DateCountValue, <"string formatting parameters">) ' return a user defined date string from the DateCounter value. i.e. give user freedom to return date the way they want, e.g. Sat, 20-May-2006 or Saturday - 20/5/2006 etc.

Really not looked at this last one very much yet and it will be left until last as it's possibly the most challenging part. :)

No doubt I've forgotten something there, but you get the idea I hope. Then end idea is to have all that functionality and make this into a Module so these methods all become commands within BM. Mind you I have to suss out how to make Modules yet as well LOL. :)


Cheers. :)


Sub_Zero(Posted 2006) [#2]
Looks interesting...

The only thing I am missing here is a date timestamp (like in UNIX timestamp), wich is a integer% value measured in number of seconds since "1970-01-01 00:00:00".

Besides that, this is great.

Hmm on second thought maybe there should be some time functions aswell (like date.Hour, date.Minute, date.Seconds) ?


u2o(Posted 2006) [#3]
DateAdd (interval, number, date) [As in VB]

I would probably have a look at the VBScript docs and see what is in use there. I know the languages are not the same, etc, but just for research purposes.


Beaker(Posted 2006) [#4]
I'd find this useful. Any plans to add some unix time stuff?


Blitzer101(Posted 2006) [#5]
Sub_Zero

The only thing I am missing here is a date timestamp (like in UNIX timestamp), wich is a integer% value measured in number of seconds since "1970-01-01 00:00:00".


Hmmm, would that not be very similar to my DayCount function/method for the date yes? Only it would be a count of seconds as you say from mid-night 1-1-1970 rather than 1-1-0001?


u2o

DateAdd (interval, number, date) [As in VB]


Not sure I quite follow exactly what that's for or rather how it works. What do the values interval & number represent? I assume that date is purely the date you want to work from? But if so in what format is that I guess just DD, MM and YYYY would be good?


Beaker

I'd find this useful. Any plans to add some unix time stuff?


To be honest when I started this I did consider briefly whether or not I'd cover time related functions and my thoughts at the time were that I could not really see the need, but did not rule it out completely. That said I think initially I'd rather keep concentrating on the date related functions and possibly revisit the time related stuff afterwards. However, please feel free to post what you have in mind time wise - particularily as I have to admit to knowing nothing about the UNIX stuff for dates or time related functions.

Thanks for the feedback - please keep it coming, I want this to be something of use to others as well as for myself so any commments are appreciated. :)


EOF(Posted 2006) [#6]
I have a set of date commands here which you might want to look at:

http://www.blitzmax.com/codearcs/codearcs.php?code=1647


u2o(Posted 2006) [#7]
Sorry, I wasn't too clear on the DateAdd.

Interval - This is the interval type to add, e.g., "d" = add days, "m" = add months, "yyyy" add years, etc

Number - This is the amount of "intervals" you want to add. e.g. as an Integer

Date - The date to add the integer of intervals to.

Pseudo:
X = DateAdd("d", 7, "25/05/2006") ' X now holds 01/06/2006

Have a peek here for a bit more info; http://msdn2.microsoft.com/en-us/hcxe65wz.aspx

Cheers


klepto2(Posted 2006) [#8]
Do you mean something like this : http://www.blitzbasic.com/Community/posts.php?topic=54935


Sub_Zero(Posted 2006) [#9]
nice.. Maybe you could merge that project?


RocketGnome(Posted 2006) [#10]
Be aware... that "seconds since 1970-01-01" is configurable (but just happens to be the default value).

The correct statement would be "seconds since the epoch"

If you want to support posix type time here's a great explanation of the hardware clock setting.

http://www.die.net/doc/linux/man/man8/hwclock.8.html


Blitzer101(Posted 2006) [#11]
u2o,

Sorry, I wasn't too clear on the DateAdd.

Interval - This is the interval type to add, e.g., "d" = add days, "m" = add months, "yyyy" add years, etc

Number - This is the amount of "intervals" you want to add. e.g. as an Integer

Date - The date to add the integer of intervals to.


Yeah something like that maybe do-able and worthwhile - thanks for the suggestion. :)