Plugin Scripting BUG: Problem using dates and floating point
Moderator: kfury77
Forum rules
Please try to follow these guidelines. This will help to receive faster and more accurate response.
Please try to follow these guidelines. This will help to receive faster and more accurate response.
- Check the Support section of the corresponding product first. Chances are you will find your answer there;
- Do not create new topics for already reported problems. Add your comments to the existing topics instead;
- Create separate topic for each problem request. Do NOT post a number of non-related problem reports in a single topic;
- Give your topic a meaningful title. Titles such as "A question," "Bug report" and "Help!" provide others no clue what your message is about;
- Include the version number of the software you are using;
- This is not an official customer support helpdesk. If you need a prompt and official response, please contact our support team directly instead. It may take a while until you receive a reply in the forum;
Plugin Scripting BUG: Problem using dates and floating point
In my latest plugin, I have a line:
var UnixStartDate = StrToDate("01/01/1970");
This works perfectly on my system, but on other systems it reports an error:
Plugin "Unix Timestamp": Line 28:5: "01/01/1970" is not a valid date
I had a similar problem a while ago, working with floating point values.
It looks like WeBuilder uses the system settings of the computer.
In Denmark where I live, we use comma as thousand seperator and point as decimal seperator and slash as date separator.
But in the US they use point as thousand separator and comma as decimal seperator.
So my plugin will work in the countries who uses the same separators as me, and fail with an error in all other countries.
var UnixStartDate = StrToDate("01/01/1970");
This works perfectly on my system, but on other systems it reports an error:
Plugin "Unix Timestamp": Line 28:5: "01/01/1970" is not a valid date
I had a similar problem a while ago, working with floating point values.
It looks like WeBuilder uses the system settings of the computer.
In Denmark where I live, we use comma as thousand seperator and point as decimal seperator and slash as date separator.
But in the US they use point as thousand separator and comma as decimal seperator.
So my plugin will work in the countries who uses the same separators as me, and fail with an error in all other countries.
Last edited by pmk65 on Sat May 14, 2016 9:34 pm, edited 2 times in total.
There are 10 types of people in the world: Those who understand binary and those who don't.
Re: Problem with using dates and float formats
I have discovered why this problem happens.
According to this site (which I use a LOT as reference when writing plugins), the default separator between dates is defined like this:
http://www.delphibasics.co.uk/RTL.asp?N ... eSeparator
DateSeparator = LOCALE_SDATE by default.
Now this poses is a BIG problem, as FastScript/WeBuilder doesn't have the commands (like: DateSeparator, TimeSeparator, ShortTimeFormat, LongDateFormat ect.) to change that.
So the values used in a plugin script can change depending on the users language setup in Windows.
This makes it hard/impossible to create plugins that use floating point or date/time operations.
According to this site (which I use a LOT as reference when writing plugins), the default separator between dates is defined like this:
http://www.delphibasics.co.uk/RTL.asp?N ... eSeparator
DateSeparator = LOCALE_SDATE by default.
Now this poses is a BIG problem, as FastScript/WeBuilder doesn't have the commands (like: DateSeparator, TimeSeparator, ShortTimeFormat, LongDateFormat ect.) to change that.
So the values used in a plugin script can change depending on the users language setup in Windows.
This makes it hard/impossible to create plugins that use floating point or date/time operations.
There are 10 types of people in the world: Those who understand binary and those who don't.
Re: Plugin Scripting BUG: Problem using dates and floating p
I'll add "DateSeparator, TimeSeparator, ShortTimeFormat, LongDateFormat" to plugins wishlist. We didn't figure someone would do a lot of date/time manipulations 

Blumentals Software Programmer
Re: Plugin Scripting BUG: Problem using dates and floating p
Btw there should be no problems with decimal values any more, WeBuilder just resets it to "." independent on locale (because Web standards e.g. CSS use . anyways). It's more complicated with the dates, I think your idea of exposing date format would be better in this case.
Blumentals Software Programmer
Re: Plugin Scripting BUG: Problem using dates and floating p
Good to know that the floading point problem has been fixed. 
I got around the Date problem by using a numeric value instead of the date object. But that only worked when converting from Unixtimestamp to date.
The other way (date to untixtimestamp) requires a known dateformat.

I got around the Date problem by using a numeric value instead of the date object. But that only worked when converting from Unixtimestamp to date.
The other way (date to untixtimestamp) requires a known dateformat.
There are 10 types of people in the world: Those who understand binary and those who don't.
Re: Plugin Scripting BUG: Problem using dates and floating p
The 4 listed functions will be added, but only in Read-only mode. There are some functions that have been there since the beginning, that might help you with dates:
and these are the ones that you know about, but I'm adding them here for reference:
Code: Select all
function EncodeDate(Year, Month, Day: Word): TDateTime
procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word)
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime
procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word)
function Date: TDateTime
function Time: TDateTime
function Now: TDateTime
function DayOfWeek(aDate: TDateTime): Integer
function IsLeapYear(Year: Word): Boolean
function DaysInMonth(nYear, nMonth: Integer): Integer
function FormatDateTime(Fmt: String; DateTime: TDateTime): String
function ValidDate(cDate: String): Boolean
Code: Select all
function DateToStr(e: Extended): String
function TimeToStr(e: Extended): String
function DateTimeToStr(e: Extended): String
function StrToDate(s: String): Extended
function StrToTime(s: String): Extended
function StrToDateTime(s: String): Extended
Blumentals Software Programmer
Re: Plugin Scripting BUG: Problem using dates and floating p
From the documentation of "StrToDateTime" (The other StrToXX functions is similar)
---
The first, date part of the string must adhere to the format of the ShortDateFormat value, and use the DateSeparator character to separate the day, month and year values.
The second, time part, separated by a blank from the date must adhere to the format of the LongTimeFormat value, and use the TimeSeparator character to separate the hour, minute and second values.
---
So I don't think a ReadOnly version will help. As without having a unified ShortDateFormat ,LongTimeFormat, TimeSeparator and DateSeparator it will be very hard to make a conversion that works on all setups.
---
The first, date part of the string must adhere to the format of the ShortDateFormat value, and use the DateSeparator character to separate the day, month and year values.
The second, time part, separated by a blank from the date must adhere to the format of the LongTimeFormat value, and use the TimeSeparator character to separate the hour, minute and second values.
---
So I don't think a ReadOnly version will help. As without having a unified ShortDateFormat ,LongTimeFormat, TimeSeparator and DateSeparator it will be very hard to make a conversion that works on all setups.
There are 10 types of people in the world: Those who understand binary and those who don't.
Re: Plugin Scripting BUG: Problem using dates and floating p
In your specific case you could use EncodeDate(1970, 1, 1) and avoid StrToDate altogether. If you are targeting a specific, locale-independent format, you could use regular expressions to split the date/time string into the components and then use EncodeDate(...) + EncodeTime(...).
Blumentals Software Programmer
Re: Plugin Scripting BUG: Problem using dates and floating p
Didn't think of that. Thanks.Aivars wrote:In your specific case you could use EncodeDate(1970, 1, 1) and avoid StrToDate altogether. If you are targeting a specific, locale-independent format, you could use regular expressions to split the date/time string into the components and then use EncodeDate(...) + EncodeTime(...).
BTW: Then I found a way to get hold of the locale settings of the system using a batch file. And then it's easy to pass the output to a plugin script.
Code: Select all
@ECHO OFF
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v sTimeFormat') DO SET TimeFormat=%%B
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v sLongDate') DO SET LongDate=%%B
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v sShortDate') DO SET ShortDate=%%B
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v sDate') DO SET DateDelimiter=%%B
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v sTime') DO SET TimeDelimiter=%%B
ECHO TimeFormat = %TimeFormat%
ECHO LongDate = %LongDate%
ECHO ShortDate = %ShortDate%
ECHO DateDelimiter = %DateDelimiter%
ECHO TimeDelimiter = %TimeDelimiter%
There are 10 types of people in the world: Those who understand binary and those who don't.