mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2026-02-04 05:54:44 +01:00
* support for east asia locale in formatdatetime. Patch from Taka_JP, mantis 14955 modified for recent sysutils rework, and to init eastasia support only once.
git-svn-id: trunk@15776 -
This commit is contained in:
parent
2d8ac256cf
commit
8caa62618f
@ -813,6 +813,44 @@ var
|
||||
ResultLen: integer;
|
||||
ResultBuffer: array[0..255] of char;
|
||||
ResultCurrent: pchar;
|
||||
{$IFDEF Windows}
|
||||
isEnable_E_Format : Boolean;
|
||||
isEnable_G_Format : Boolean;
|
||||
eastasiainited : boolean;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF Windows}
|
||||
procedure InitEastAsia;
|
||||
var ALCID : LCID;
|
||||
PriLangID , SubLangID : Word;
|
||||
|
||||
begin
|
||||
ALCID := GetThreadLocale;
|
||||
PriLangID := ALCID and $3FF;
|
||||
if (PriLangID>0) then
|
||||
SubLangID := (ALCID and $FFFF) shr 10
|
||||
else
|
||||
begin
|
||||
PriLangID := SysLocale.PriLangID;
|
||||
SubLangID := SysLocale.SubLangID;
|
||||
end;
|
||||
isEnable_E_Format := (PriLangID = LANG_JAPANESE)
|
||||
or
|
||||
(PriLangID = LANG_KOREAN)
|
||||
or
|
||||
((PriLangID = LANG_CHINESE)
|
||||
and
|
||||
(SubLangID = SUBLANG_CHINESE_TRADITIONAL)
|
||||
);
|
||||
isEnable_G_Format := (PriLangID = LANG_JAPANESE)
|
||||
or
|
||||
((PriLangID = LANG_CHINESE)
|
||||
and
|
||||
(SubLangID = SUBLANG_CHINESE_TRADITIONAL)
|
||||
);
|
||||
eastasiainited :=true;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure StoreStr(Str: PChar; Len: Integer);
|
||||
begin
|
||||
@ -855,6 +893,7 @@ var
|
||||
var
|
||||
Year, Month, Day, DayOfWeek, Hour, Minute, Second, MilliSecond: word;
|
||||
|
||||
|
||||
procedure StoreFormat(const FormatStr: string; Nesting: Integer; TimeFlag: Boolean);
|
||||
var
|
||||
Token, lastformattoken: char;
|
||||
@ -868,6 +907,7 @@ var
|
||||
begin
|
||||
if Nesting > 1 then // 0 is original string, 1 is included FormatString
|
||||
Exit;
|
||||
|
||||
FormatCurrent := PChar(FormatStr);
|
||||
FormatEnd := FormatCurrent + Length(FormatStr);
|
||||
Clock12 := false;
|
||||
@ -1019,8 +1059,36 @@ var
|
||||
begin
|
||||
StoreString(' ');
|
||||
StoreFormat(FormatSettings.LongTimeFormat, Nesting+1, True);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{$IFDEF Windows}
|
||||
'E':
|
||||
begin
|
||||
if not Eastasiainited then InitEastAsia;
|
||||
if Not(isEnable_E_Format) then StoreStr(@FormatCurrent^, 1)
|
||||
else
|
||||
begin
|
||||
while (P < FormatEnd) and (UpCase(P^) = Token) do
|
||||
P := P + 1;
|
||||
Count := P - FormatCurrent;
|
||||
StoreString(ConvertEraYearString(Count,Year,Month,Day));
|
||||
end;
|
||||
lastformattoken:=token;
|
||||
end;
|
||||
'G':
|
||||
begin
|
||||
if not Eastasiainited then InitEastAsia;
|
||||
if Not(isEnable_G_Format) then StoreStr(@FormatCurrent^, 1)
|
||||
else
|
||||
begin
|
||||
while (P < FormatEnd) and (UpCase(P^) = Token) do
|
||||
P := P + 1;
|
||||
Count := P - FormatCurrent;
|
||||
StoreString(ConvertEraString(Count,Year,Month,Day));
|
||||
end;
|
||||
lastformattoken:=token;
|
||||
end;
|
||||
{$ENDIF}
|
||||
end;
|
||||
lastformattoken := token;
|
||||
end;
|
||||
@ -1032,6 +1100,9 @@ var
|
||||
end;
|
||||
|
||||
begin
|
||||
{$ifdef windows}
|
||||
eastasiainited:=false;
|
||||
{$endif}
|
||||
DecodeDateFully(DateTime, Year, Month, Day, DayOfWeek);
|
||||
DecodeTime(DateTime, Hour, Minute, Second, MilliSecond);
|
||||
ResultLen := 0;
|
||||
|
||||
@ -150,6 +150,9 @@ function GetFileVersion(const AFileName:string):Cardinal;
|
||||
{$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
|
||||
{$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
|
||||
|
||||
|
||||
function ConvertEraYearString(Count ,Year,Month,Day : integer) : string; forward;
|
||||
function ConvertEraString(Count ,Year,Month,Day : integer) : string; forward;
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -646,6 +649,72 @@ begin
|
||||
Result := Def;
|
||||
end;
|
||||
|
||||
function ConvertEraString(Count ,Year,Month,Day : integer) : string;
|
||||
var
|
||||
ASystemTime: TSystemTime;
|
||||
buf: array[0..100] of char;
|
||||
ALCID : LCID;
|
||||
PriLangID : Word;
|
||||
SubLangID : Word;
|
||||
begin
|
||||
Result := ''; if (Count<=0) then exit;
|
||||
DateTimeToSystemTime(EncodeDate(Year,Month,Day),ASystemTime);
|
||||
|
||||
ALCID := GetThreadLocale;
|
||||
// ALCID := SysLocale.DefaultLCID;
|
||||
if GetDateFormat(ALCID , DATE_USE_ALT_CALENDAR
|
||||
, @ASystemTime, PChar('gg')
|
||||
, @buf, SizeOf(buf)) > 0 then
|
||||
begin
|
||||
Result := buf;
|
||||
if Count = 1 then
|
||||
begin
|
||||
PriLangID := ALCID and $3FF;
|
||||
SubLangID := (ALCID and $FFFF) shr 10;
|
||||
case PriLangID of
|
||||
LANG_JAPANESE:
|
||||
begin
|
||||
Result := Copy(WideString(Result),1,1);
|
||||
end;
|
||||
LANG_CHINESE:
|
||||
if (SubLangID = SUBLANG_CHINESE_TRADITIONAL) then
|
||||
begin
|
||||
Result := Copy(WideString(Result),1,1);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
// if Result = '' then Result := StringOfChar('G',Count);
|
||||
end;
|
||||
|
||||
function ConvertEraYearString(Count ,Year,Month,Day : integer) : string;
|
||||
var
|
||||
ALCID : LCID;
|
||||
ASystemTime : TSystemTime;
|
||||
AFormatText : string;
|
||||
buf : array[0..100] of Char;
|
||||
begin
|
||||
Result := '';
|
||||
DateTimeToSystemTime(EncodeDate(Year,Month,Day),ASystemTime);
|
||||
|
||||
if Count <= 2 then
|
||||
AFormatText := 'yy'
|
||||
else
|
||||
AFormatText := 'yyyy';
|
||||
|
||||
ALCID := GetThreadLocale;
|
||||
// ALCID := SysLocale.DefaultLCID;
|
||||
|
||||
if GetDateFormat(ALCID, DATE_USE_ALT_CALENDAR
|
||||
, @ASystemTime, PChar(AFormatText)
|
||||
, @buf, SizeOf(buf)) > 0 then
|
||||
begin
|
||||
Result := buf;
|
||||
if (Count = 1) and (Result[1] = '0') then
|
||||
Result := Copy(Result, 2, Length(Result)-1);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Function GetLocaleInt(LID,TP,Def: LongInt): LongInt;
|
||||
Var
|
||||
|
||||
Loading…
Reference in New Issue
Block a user