Page 1 of 1
TimeStamp format issue with am/pm.
Posted: Mon 25 Jun 2012 11:29
by MarkF
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
Re: TimeStamp format issue with am/pm.
Posted: Tue 26 Jun 2012 12:55
by AlexP
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
Re: TimeStamp format issue with am/pm.
Posted: Tue 26 Jun 2012 13:19
by MarkF
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
Re: TimeStamp format issue with am/pm.
Posted: Wed 27 Jun 2012 08:49
by AlexP
hello,
We have implemented this feature, it will be included into the next version of ODAC
Re: TimeStamp format issue with am/pm.
Posted: Fri 29 Jun 2012 12:27
by MarkF
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:
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
-Mark
Re: TimeStamp format issue with am/pm.
Posted: Mon 02 Jul 2012 09:29
by AlexP
hello,
Thank you for the example, to resolve the problem we used practically a similar code.
Re: TimeStamp format issue with am/pm.
Posted: Mon 06 Aug 2012 13:16
by MarkF
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:
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';
and a bit later:
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;
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.
Re: TimeStamp format issue with am/pm.
Posted: Tue 07 Aug 2012 09:14
by AlexP
hello,
Thank you for the information, we will fix the TimeStamp format forming case-sensitively in the next version.