PDA

View Full Version : dt_setdateseparator not working?



fmaxwell
29-03-2008, 03:53
When I use DT_SetDateSeparator("/"), dates returned from DT_SecToDate are returned with hyphens rather than the specified forward slash. Is this the expected behavior and, if so, what does DT_SetDateSeparator do?

Thanks in advance.

I am running version 1.6.0.0.

matthew
29-03-2008, 05:09
Hi fmaxwell :)

You might find the following program useful it uses DT_SecToDate to display the current date & places a forward-slash between the different parts.



' thinBASIC GUI file

uses "DT"

dim s as string

s = dt_sectodate(dt_datetosec(""))

msgbox 0, dt_dateformat(s, "yyyy/MM/dd")

ErosOlmi
29-03-2008, 09:15
Ciao fmaxwell and welcome here.

I will check asap your problem and give you back.

ErosOlmi
29-03-2008, 09:40
fmaxwell,

I made some quick check.
dt_setdateseparator function set the date separator but that separator is used only when DT_DateFormat is executed without any format.
For example in DT_DateFormat("06.04.2005", ""). In this case, because there is now format, the indicated separator is used.

Can you please post a little example not working for you?
It can help me whet's going wrong.

Thanks
Eros

PS: DT module help is very bad. I need to rewrite it absolutely! Sorry.

fmaxwell
29-03-2008, 12:39
ErosOlmi,

The DT stuff is really quite good compared to what one finds in most languages. The primary problem I have had with it has to do with documentation. I needed to convert from one time format to another. The first, a ground station for satellites that runs a language called STOL (Satellite Test and Operations Language), stores time as the number of seconds since 1/1/1970 at 12AM. The other (Excel) stores time as a floating point number equal to 2 + number of days since 1/1/1900 (Excel reproduces Lotus 123 bugs that counted 1/1/1900 as a leap year {it was not} and started numbering at 1 instead of 0). In addition, I needed to be able to display and process the dates within thinBasic. It's all up and running and works beautifully, but I never did find an indication of what thinBasic's native time storage format is (number of seconds since what?).

Here's a code snippet:






DT_SetDateSeparator("/")
...
TBTime = ThisTlmLine(1) + DT_DateToSec("01/01/1970") ' Get timestamp and adjust for different time bases.
TB_Datestring = DT_SecToDate(TBTime) ' Create ThinBasic datestamp




What I expected to get out of there was a date in the format mm/dd/yyyy. Instead, I got one formatted as mm-dd-yyyy.

It was easy enough to fix:




TBTime = ThisTlmLine(1) + DT_DateToSec("01-01-1970") ' Get timestamp and adjust for different time bases.
TB_Datestring = DT_Dateformat (DT_SecToDate(TBTime), "MM/dd/yyyy" ) ' Create ThinBasic datestamp




I'd really like to see the DT_SetDateSeparator function affect everything that accepts or produces a date. For example, the following should work:




DT_SetDateSeparator("@")
'---Results "06@13@2005"
MsgBox 0, DT_SecToDate(DT_DateToSec("06@13@05"))




Note about documentation bug: Help file says that the format should be "Dd" for day of month as digits with leading zero for single-digit days., but it really is "dd." "Dd" will give you a day formatted with a letter D in front of it.

If you do rewrite the DT function, PLEASE let it handle fractions of seconds. I would love to be able to get time as hh:mm:ss.sss, for example. Also, what about conversions, in and out, for common date and time storage formats, such as Unix and Excel? Maybe even create a function to specify a format (epoch, time unit, offset, data type -- example for Unix time format: epoch: 1/1/1970 00:00:00, units: seconds, offset: 0, data type: Long)

P.S. I've been a software engineer since 1980. thinBasic is the first new language I've found in years that I've really been excited by. Thank you!

Regards,
Fred

ErosOlmi
29-03-2008, 15:32
Well,

first thanks for your nice comment.

Usually, when we create a module, we do not put much in there unless we really need it. What we do is to listen to other people using it and get feedback, suggestions, bug fixes. Now it seems you did a lot of work with thinBasic and DT module. Also your suggestions are very very interesting. I will discuss with Roberto (DT module creator) about this and give you back. Maybe time to re-think some code and how we implemented.

Ciao
Eros

PS: I've created a new child forum dedicated to Dates and moved you original post here.

RobertoBianchi
30-03-2008, 18:30
Hi Fred,

as Eros said until now the DT_SetDateSeparator() function sets the date separator used only by DT_DateFormat() but you are right, better to extend the use of it also into DT_SecToDate() function, sure I'll do that ASAP.
Instead I don't know how handle fractions of seconds, I need to study, may be a solution could be using msec instead of seconds in all calculations but I'm not sure.
Also I'll have to check Unix time format.

regards,
Roberto

RobertoBianchi
31-03-2008, 09:25
Fred,

as request the DT_SecToDate() has been changed, you'll find this update in the next ThinBasic release.

Bye,
Roberto

fmaxwell
01-04-2008, 03:06
Fred,

as request the DT_SecToDate() has been changed, you'll find this update in the next ThinBasic release.

Bye,
Roberto


You guys are great! Thanks so much. If you get people whining because it breaks things, please feel free to send them to me and I'll flame them for you. ;)

RobertoBianchi
01-04-2008, 08:19
Fred,

changed also the DT_TimeToSec() behavior in order to work with the DT_SetTimeSeparator().
Added the DT_GetTime() function that returns time in the following format: hh:mm:ss.mmm, DT_TimeToMillisec() and DT_MillisecToTime() for work with it as show below:


uses "DT"

DIM sTimeString as string
DIM sTimeString1 as string
dim nMillisecond as ext

DT_SetDateSeparator("@")
'---Results "06@13@2005"
MsgBox 0, DT_SecToDate(DT_DateToSec("06@13@05"))

sTimeString = DT_GetTime()

MsgBox 0, sTimeString, %MB_OK, "Result of DT_GetTime()"

nMillisecond = DT_TimeToMillisec(sTimeString)

MsgBox 0, nMillisecond, %MB_OK, "Result of DT_TimeToMillisec()"

sTimeString1 = DT_MillisecToTime(nMillisecond)

MsgBox 0, sTimeString + $CRLF + sTimeString1, %MB_OK, "Result of DT_MillisecToTime()"


Ciao,
Roberto

ErosOlmi
01-04-2008, 11:18
@Roberto
Thanks. I will update module (and other matters) asap when released new thinBasic preview version.

@Fred
Please download attached file in Roberto's post and replace your current local file under \thinBasic\Lib\. It is the new version of DT (Date) module.

Ciao
Eros

fmaxwell
01-04-2008, 21:32
@Roberto
Thanks. I will update module (and other matters) asap when released new thinBasic preview version.

@Fred
Please download attached file in Roberto's post and replace your current local file under \thinBasic\Lib\. It is the new version of DT (Date) module.


Roberto and Eros,

Thanks so much for this and for turning the change around so quickly.

I've installed and tested it and it works exactly right, with the date separator working just like one would expect.

The milliseconds code is a really nice addition to thinBasic, making it practical for timing applications that it could never be used for previously.

If you ever consider a major rewrite of DT (or a new module): Consider using floating point to store a single value for both the date and time. Everything to the left of the decimal point could be the number of seconds from a starting date (example: 1/1/2000 at 12AM) and everything to the right could be the fractional second. That would prevent the situation of rollover occurring between the time your code checks the time and date (e.g., time checked at 23:59:59.995 and date checked 50ms later, after it rolled over).

So one floating point number would contain the date and time to a resolution of milliseconds. Every other routine could work from that standard time representation. You could lose the DT_SecToDate, DT_SecToTime, etc. and just have DT_DateTimeFormat work with the numeric value to produce the string:


uses "DT"

DIM RightNow as DOUBLE
DIM Later as DOUBLE
DIM TimeDateStr as STRING
DIM DateOnlyFormat as STRING VALUE "mmm dd, yyyy"
DIM TimeDateFormat as STRING VALUE (DateOnlyFormat & " " & TimeOnlyFormat)

RightNow = DT_GetTimestamp ' Get the current time

msgbox 0, DT_DateTimeFormat(RightNow, TimeDateFormat), "The current date and time"
msgbox 0, DT_DateTimeFormat(RightNow + (2 * %week), DateOnlyFormat), "The date in two weeks"
msgbox 0, DT_DateTimeFormat(RightNow + (15.5 * %minute), TimeOnlyFormat), "The time in 15.5 minutes"
msgbox 0, DT_DateTimeFormat(RightNow + (%week + 3 * %day + 16 * %hour * 5 * %min + 26.122), TimeDateFormat), "The date and time in 1 week, 3 days, 16 hours, 5 minutes, and 26.122 seconds"


I realize that it's a whole different way of handling the date and time, but I just wanted to pass the idea along. If it's just way too big a change, or if it's just not a good idea, I fully understand.

Thanks.

Regards,
Fred