TimeStamp format issue with am/pm.
TimeStamp format issue with am/pm.
The TOraTimeStamp.SetFormat procedure currently only handles time formats where the AMPM indicator is given as "AMPM". Delphi supports 3 options for indicating the AMPM (this is copied from the Delphi help):
am/pm
Uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' for any hour before noon, and 'pm' for any hour after noon. The am/pm specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
a/p
Uses the 12-hour clock for the preceding h or hh specifier, and displays 'a' for any hour before noon, and 'p' for any hour after noon. The a/p specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
ampm
Uses the 12-hour clock for the preceding h or hh specifier, and displays the contents of the TimeAMString global variable for any hour before noon, and the contents of the TimePMString global variable for any hour after noon.
Currently the TOraTimeStamp.SetFormat procedure only handles the third case (although it uses hardcoded AM and PM instead of the variables.) It really needs to be able to handle the first two as well. It's common to have the FormatSettings.LongTimeFormat set to something like:
hh:nn:ss am/pm
which currently fails in odac.
-Mark
am/pm
Uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' for any hour before noon, and 'pm' for any hour after noon. The am/pm specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
a/p
Uses the 12-hour clock for the preceding h or hh specifier, and displays 'a' for any hour before noon, and 'p' for any hour after noon. The a/p specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
ampm
Uses the 12-hour clock for the preceding h or hh specifier, and displays the contents of the TimeAMString global variable for any hour before noon, and the contents of the TimePMString global variable for any hour after noon.
Currently the TOraTimeStamp.SetFormat procedure only handles the third case (although it uses hardcoded AM and PM instead of the variables.) It really needs to be able to handle the first two as well. It's common to have the FormatSettings.LongTimeFormat set to something like:
hh:nn:ss am/pm
which currently fails in odac.
-Mark
Re: TimeStamp format issue with am/pm.
hello,
For defining AM/PM Oracle can accept one of the following values (AM or PM, or A.M. or P.M.), and we don't change the format string set by user, it is transferred to the server as is.
Therefore, for defining the time format, you should use the given values. You can find more details in the article
For defining AM/PM Oracle can accept one of the following values (AM or PM, or A.M. or P.M.), and we don't change the format string set by user, it is transferred to the server as is.
Therefore, for defining the time format, you should use the given values. You can find more details in the article
Re: TimeStamp format issue with am/pm.
Hi Alex,
It seems you didn't understand my post, this relates to converting the Delphi format to the Oracle format. You need to rewrite the TOraTimeStamp.SetFormat procedure (which converts a Delphi time format to the corresponding Oracle format) so that it supports all the formats that Delphi allows. It currently fails on am/pm as I pointed out. I've already rewritten the procedure (it took all of 5 minutes) but it would be best if you took care of it as well to help all of your customers. If you'd like to test the problem just set your Delphi FormatSettings.LongTimeFormat to 'hh:nn:ss am/pm' and retrieve a timestamp value from Oracle as a string (TOraTimeStampField(Field).AsString).
-Mark
It seems you didn't understand my post, this relates to converting the Delphi format to the Oracle format. You need to rewrite the TOraTimeStamp.SetFormat procedure (which converts a Delphi time format to the corresponding Oracle format) so that it supports all the formats that Delphi allows. It currently fails on am/pm as I pointed out. I've already rewritten the procedure (it took all of 5 minutes) but it would be best if you took care of it as well to help all of your customers. If you'd like to test the problem just set your Delphi FormatSettings.LongTimeFormat to 'hh:nn:ss am/pm' and retrieve a timestamp value from Oracle as a string (TOraTimeStampField(Field).AsString).
-Mark
Re: TimeStamp format issue with am/pm.
hello,
We have implemented this feature, it will be included into the next version of ODAC
We have implemented this feature, it will be included into the next version of ODAC
Re: TimeStamp format issue with am/pm.
Hi Alex,
Thanks! Note that when handling the AM/PM marker that it should preserve the case of the marker supplied (I use this to get a lowercase am or pm indicator.) So the code should look something like:
-Mark
Thanks! Note that when handling the AM/PM marker that it should preserve the case of the marker supplied (I use this to get a lowercase am or pm indicator.) So the code should look something like:
Code: Select all
else if AnsiCompareText('AM/PM', Copy(Str, P, 5)) = 0 then begin
FFormat := FFormat + Copy(Str, P, 2); // Preserve case of the AM part.
Inc(P, 5);
end
Re: TimeStamp format issue with am/pm.
hello,
Thank you for the example, to resolve the problem we used practically a similar code.
Thank you for the example, to resolve the problem we used practically a similar code.
Re: TimeStamp format issue with am/pm.
Hi Alex,
I just checked the source code of 8.2.8 and unfortunately they didn't use my code suggestion (or a "practically similar code") and so the current version doesn't work correctly. As I pointed out it needs to detect AM/PM indicators in a case insensitive way and also preserve that case. The first code section below shows that the first three checks should be case insensitive. The second code section repeats my earlier code to preserve the case of the AM/PM indicator.
So the two code sections should be:
and a bit later:
It would be great if that could be fixed for the next release. I'm sure you can understand that it's a bit frustrating to take the time to report an issue, include the code to fix it, and have it still not be fixed correctly.
I just checked the source code of 8.2.8 and unfortunately they didn't use my code suggestion (or a "practically similar code") and so the current version doesn't work correctly. As I pointed out it needs to detect AM/PM indicators in a case insensitive way and also preserve that case. The first code section below shows that the first three checks should be case insensitive. The second code section repeats my earlier code to preserve the case of the AM/PM indicator.
So the two code sections should be:
Code: Select all
StrTemp := UpperCase(Str); // Added var StrTemp
if
(AnsiPos('AMPM', StrTemp) = 0) and
(AnsiPos('AM/PM', StrTemp) = 0) and
(AnsiPos('A/P', StrTemp) = 0) and
(AnsiPos('t', {$IFDEF VER16P}FormatSettings.{$ENDIF}LongTimeFormat) = 0) then
Temp := '24'
else
Temp := '12';
Code: Select all
if AnsiCompareText('AMPM', Copy(Str, P, 4)) = 0 then begin
FFormat := FFormat + 'AM';
Inc(P, 4);
end
else if AnsiCompareText('AM/PM', Copy(Str, P, 5)) = 0 then begin
// FFormat := FFormat + 'AM';
FFormat := FFormat + Copy(Str, P, 2); // Preserve case!
Inc(P, 5);
end
else if AnsiCompareText('A/P', Copy(Str, P, 3)) = 0 then begin
FFormat := FFormat + 'AM';
Inc(P, 3);
end
else begin
FFormat := FFormat + UpperCase(Str[P]);
Inc(P);
end;
Re: TimeStamp format issue with am/pm.
hello,
Thank you for the information, we will fix the TimeStamp format forming case-sensitively in the next version.
Thank you for the information, we will fix the TimeStamp format forming case-sensitively in the next version.