Voici plusieurs solutions pour étendre la fonction FormatDate() vers un FormatDate() localisé.
Code : Tout sélectionner
; Ce source propose 3 solutions pour PureBasic 4.02.
;
; %dd -> 01
; %ddd -> Lun.
; %dddd -> Lundi
; %mm -> 01
; %mmm -> Jan.
; %mmmm -> Janvier
Import "kernel32.lib"
GetCalendarInfoA(lcID.l, calID.l, calType.l, *lpCalData, cchData.l, *lpValue)
EndImport
Procedure.s GetCalendarInfo(type.l) ; Windows 98 et plus.
Protected result.s = Space(64)
If GetCalendarInfoA(#LOCALE_USER_DEFAULT, #CAL_GREGORIAN, type, @result, 64, 0)
ProcedureReturn UCase(Left(result, 1)) + Right(result, Len(result) - 1)
EndIf
EndProcedure
Procedure.s GetDateFormat(mask.s, date.l) ; Windows 95 et plus.
Protected st.SYSTEMTIME, result.s = Space(64)
st\wDay = Day (date)
st\wMonth = Month(date)
st\wYear = Year (date)
If GetDateFormat_(#LOCALE_USER_DEFAULT, 0, @st, mask, @result, 64)
ProcedureReturn UCase(Left(result, 1)) + Right(result, Len(result) - 1)
EndIf
EndProcedure
Procedure.s FormatDate1(mask.s, date.l) ; Version FR - Cross-Platform.
mask = ReplaceString(mask, "%dddd", StringField("Dimanche,Lundi,Mardi,Mercredi,Jeudi,Vendredi,Samedi", DayOfWeek(date) + 1, ","))
mask = ReplaceString(mask, "%ddd", StringField("Dim.,Lun.,Mar.,Mer.,Jeu.,Ven.,Sam.", DayOfWeek(date) + 1, ","))
mask = ReplaceString(mask, "%mmmm", StringField("Janvier,Février,Mars,Avril,Mai,Juin,Juillet,Août,Septembre,Octobre,Novembre,Décembre", Month(date), ","))
mask = ReplaceString(mask, "%mmm", StringField("Janv.,Févr.,Mars,Avr.,Mai,Juin,Juil.,Août,Sept.,Oct.,Nov.,Déc.", Month(date), ","))
ProcedureReturn FormatDate(mask, date)
EndProcedure
Procedure.s FormatDate2(mask.s, date.l) ; Windows 95 - Localisation via GetDateFormat()
mask = ReplaceString(mask, "%dddd", GetDateFormat("dddd", date))
mask = ReplaceString(mask, "%ddd", GetDateFormat("ddd", date))
mask = ReplaceString(mask, "%mmmm", GetDateFormat("MMMM", date))
mask = ReplaceString(mask, "%mmm", GetDateFormat("MMM", date))
ProcedureReturn FormatDate(mask, date)
EndProcedure
Procedure.s FormatDate3(mask.s, date.l) ; Windows 98 - Localisation via GetCalendarInfo()
mask = ReplaceString(mask, "%dddd", GetCalendarInfo(#CAL_SDAYNAME1 + DayOfWeek(date) - 1))
mask = ReplaceString(mask, "%ddd", GetCalendarInfo(#CAL_SABBREVDAYNAME1 + DayOfWeek(date) - 1))
mask = ReplaceString(mask, "%mmmm", GetCalendarInfo(#CAL_SMONTHNAME1 + Month(date) - 1))
mask = ReplaceString(mask, "%mmm", GetCalendarInfo(#CAL_SABBREVMONTHNAME1 + Month(date) - 1))
ProcedureReturn FormatDate(mask, date)
EndProcedure
Debug FormatDate1("%ddd %dd %mmm %yyyy %hh:%ii:%ss", Date())
Debug FormatDate2("%ddd %dd %mmm %yyyy %hh:%ii:%ss", Date())
Debug FormatDate3("%ddd %dd %mmm %yyyy %hh:%ii:%ss", Date())
Debug FormatDate1("%dddd %dd %mmmm %yyyy %hh:%ii:%ss", Date())
Debug FormatDate2("%dddd %dd %mmmm %yyyy %hh:%ii:%ss", Date())
Debug FormatDate3("%dddd %dd %mmmm %yyyy %hh:%ii:%ss", Date())