Browse Source

Factoring out TryStrToDateTimeStandard

Source commit: 8773a6357b7b6c65b2abc09e2463a1bb25ca303d
Martin Prikryl 7 years ago
parent
commit
86971f7e4c
3 changed files with 13 additions and 7 deletions
  1. 11 0
      source/core/Common.cpp
  2. 1 0
      source/core/Common.h
  3. 1 7
      source/core/FileMasks.cpp

+ 11 - 0
source/core/Common.cpp

@@ -1864,6 +1864,17 @@ bool __fastcall TryRelativeStrToDateTime(UnicodeString S, TDateTime & DateTime,
   return Result;
 }
 //---------------------------------------------------------------------------
+bool TryStrToDateTimeStandard(const UnicodeString & S, TDateTime & Value)
+{
+  TFormatSettings FormatSettings = TFormatSettings::Create(GetDefaultLCID());
+  FormatSettings.DateSeparator = L'-';
+  FormatSettings.TimeSeparator = L':';
+  FormatSettings.ShortDateFormat = "yyyy/mm/dd";
+  FormatSettings.ShortTimeFormat = "hh:nn:ss";
+
+  return TryStrToDateTime(S, Value, FormatSettings);
+}
+//---------------------------------------------------------------------------
 const wchar_t KiloSize = L'K';
 const wchar_t MegaSize = L'M';
 const wchar_t GigaSize = L'G';

+ 1 - 0
source/core/Common.h

@@ -139,6 +139,7 @@ bool __fastcall IsUWP();
 TLibModule * __fastcall FindModule(void * Instance);
 __int64 __fastcall Round(double Number);
 bool __fastcall TryRelativeStrToDateTime(UnicodeString S, TDateTime & DateTime, bool Add);
+bool TryStrToDateTimeStandard(const UnicodeString & S, TDateTime & Value);
 bool __fastcall TryStrToSize(UnicodeString SizeStr, __int64 & Size);
 UnicodeString __fastcall SizeToStr(__int64 Size);
 LCID __fastcall GetDefaultLCID();

+ 1 - 7
source/core/FileMasks.cpp

@@ -573,15 +573,9 @@ void __fastcall TFileMasks::CreateMask(
         Boundary = TMask::Open;
       }
 
-      TFormatSettings FormatSettings = TFormatSettings::Create(GetDefaultLCID());
-      FormatSettings.DateSeparator = L'-';
-      FormatSettings.TimeSeparator = L':';
-      FormatSettings.ShortDateFormat = "yyyy/mm/dd";
-      FormatSettings.ShortTimeFormat = "hh:nn:ss";
-
       TDateTime Modification;
       __int64 DummySize;
-      if ((!TryStrToInt64(PartStr, DummySize) && TryStrToDateTime(PartStr, Modification, FormatSettings)) ||
+      if ((!TryStrToInt64(PartStr, DummySize) && TryStrToDateTimeStandard(PartStr, Modification)) ||
           TryRelativeStrToDateTime(PartStr, Modification, false))
       {
         TMask::TMaskBoundary & ModificationMask =