From 94144e9e61930f170abce1574928cb416080e2f5 Mon Sep 17 00:00:00 2001 From: zoran-vucenovic Date: Wed, 27 Nov 2013 13:55:36 +0000 Subject: [PATCH] Improving detection of default date display order. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2854 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../trunk/zvdatetimepicker.pas | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/components/ZVDateTimeCtrls/trunk/zvdatetimepicker.pas b/components/ZVDateTimeCtrls/trunk/zvdatetimepicker.pas index a624598ed..fc4a5be81 100644 --- a/components/ZVDateTimeCtrls/trunk/zvdatetimepicker.pas +++ b/components/ZVDateTimeCtrls/trunk/zvdatetimepicker.pas @@ -1636,29 +1636,55 @@ end; procedure TCustomZVDateTimePicker.AdjustEffectiveDateDisplayOrder; var S: String; - I: Integer; + I, J, Le: Integer; + InQuoteChar: Char; begin if FDateDisplayOrder = ddoTryDefault then begin S := DefaultFormatSettings.ShortDateFormat; FEffectiveDateDisplayOrder := ddoTryDefault; repeat + InQuoteChar := Chr(0); + Le := Length(S); + + I := 0; + while I < Le do begin + Inc(I); + if InQuoteChar = Chr(0) then begin + case S[I] of + '''', '"': + InQuoteChar := S[I]; + 'D', 'd': + begin + { If 3 or more "d"-s are standing together, then it's day + of week, but here we are interested in day of month. + So, we have to see what is following: } + J := I + 1; + while (J <= Le) and (upCase(S[J]) = 'D') do + Inc(J); + + if J <= I + 2 then begin + FEffectiveDateDisplayOrder := ddoDMY; + Break; + end; + + I := J - 1; + end; + 'M', 'm': + begin + FEffectiveDateDisplayOrder := ddoMDY; + Break; + end; + 'Y', 'y': + begin + FEffectiveDateDisplayOrder := ddoYMD; + Break; + end; + end; + end else + if S[I] = InQuoteChar then + InQuoteChar := Chr(0); - for I := 1 to Length(S) do begin - case upCase(S[I]) of - 'D': begin - FEffectiveDateDisplayOrder := ddoDMY; - Break; - end; - 'M': begin - FEffectiveDateDisplayOrder := ddoMDY; - Break; - end; - 'Y': begin - FEffectiveDateDisplayOrder := ddoYMD; - Break; - end; - end; end; if FEffectiveDateDisplayOrder = ddoTryDefault then begin