1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| {Fonction Str -> DateTime fonctionnant avec un Format Setting. Remplace StrToDateTime car elle marche pas. On la réécrit donc.}
{Prise en compte de MyFormatSettings.ShortDateFormat et MyFormatSettings.LongTimeFormat en prenant en compte que TDateTime est la concaténation des deux séparées par un espace}
{Uniquement prise en compte de yyyy, MM, dd, hh, mm, ss -> le reste viendra plus tard en fonction des besoins}
Function PNStrToDateTime(const S:string;const FormatSettings:TFormatSettings):TDateTime;
Var
DateTemp: String;
FormatTemp: String;
DateToReturn: TDateTime;
PosC: Integer;
LongS: Integer;
LongF: Integer;
Traite: Boolean;
FormatTrait: String;
Annee: String;
Mois: String;
Jour: String;
Heure: String;
Minute: String;
Seconde: String;
SeparaDate: Char;
SeparaHeure: Char;
Begin
FormatTemp:=FormatSettings.ShortDateFormat+' '+FormatSettings.LongTimeFormat;
SeparaDate:=FormatSettings.DateSeparator;
SeparaHeure:=FormatSettings.TimeSeparator;
LongS:=Length(S);
{Prise en compte yyyy}
FormatTrait:='yyyy';
LongF:=Length(FormatTrait);
PosC:=Pos(FormatTrait,FormatTemp);
Traite:=(PosC>0) And (PosC+LongF-1<=LongS);
If Traite Then
Annee:=Copy(S,PosC,LongF)
Else
Annee:='1900';
{Prise en compte MM}
FormatTrait:='MM';
LongF:=Length(FormatTrait);
PosC:=Pos(FormatTrait,FormatTemp);
Traite:=(PosC>0) And (PosC+LongF-1<=LongS);
If Traite Then
Mois:=Copy(S,PosC,LongF)
Else
Mois:='01';
{Prise en compte dd}
FormatTrait:='dd';
LongF:=Length(FormatTrait);
PosC:=Pos(FormatTrait,FormatTemp);
Traite:=(PosC>0) And (PosC+LongF-1<=LongS);
If Traite Then
Jour:=Copy(S,PosC,LongF)
Else
Jour:='01';
{Prise en compte hh}
FormatTrait:='hh';
LongF:=Length(FormatTrait);
PosC:=Pos(FormatTrait,FormatTemp);
Traite:=(PosC>0) And (PosC+LongF-1<=LongS);
If Traite Then
Heure:=Copy(S,PosC,LongF)
Else
Heure:='12';
{Prise en compte mm}
FormatTrait:='mm';
LongF:=Length(FormatTrait);
PosC:=Pos(FormatTrait,FormatTemp);
Traite:=(PosC>0) And (PosC+LongF-1<=LongS);
If Traite Then
Minute:=Copy(S,PosC,LongF)
Else
Minute:='00';
{Prise en compte ss}
FormatTrait:='ss';
LongF:=Length(FormatTrait);
PosC:=Pos(FormatTrait,FormatTemp);
Traite:=(PosC>0) And (PosC+LongF-1<=LongS);
If Traite Then
Seconde:=Copy(S,PosC,LongF)
Else
Seconde:='00';
DateTemp:=Jour+SeparaDate+Mois+SeparaDate+Annee+' '+Heure+SeparaHeure+Minute+SeparaHeure+Seconde;
DateToReturn:=StrToDateTime(DateTemp);
PNStrToDateTime:=DateToReturn;
End; |
Partager