DATETIMEPICKER : AJOUT DE FONCTIONS

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 - 24 avril 2009 à 19:18
cavalier2400 Messages postés 120 Date d'inscription mardi 8 juillet 2008 Statut Membre Dernière intervention 1 décembre 2010 - 14 juil. 2009 à 09:39
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/49903-datetimepicker-ajout-de-fonctions

cavalier2400 Messages postés 120 Date d'inscription mardi 8 juillet 2008 Statut Membre Dernière intervention 1 décembre 2010 1
14 juil. 2009 à 09:39
il y'a de fct dans DateUtils pour le choix du 1er Jours de la semaine, j'utilise ces deux fonctions pour mon agenda de bureau, et je réussi le décalage, puisque le week end ici est un vendredi.
jw// est le jour de la semaine
y //est la date courante du date time picker // le décalage des semaines se fait toujours à partir du lundi jour numéro un...

placer les divers labels pour tester,

procedure testj( d:string);
var js1:integer;
begin
rdv1.Monthcalendar1.date:= strtodate(d);
if dayoftheweek(rdv1.Monthcalendar1.date - 5) >0 then js1:= dayoftheweek(rdv1.Monthcalendar1.date - 5)
else js1:= js1+2;
jw:=js1;
end;
procedure cadrelejour();
begin
testj(datetostr(rdv1.monthcalendar1.Date));
if weekof(rdv1.monthcalendar1.Date+2)= weekof(date()+2) then

begin
testj(datetostr(date()));
if jw=1 then begin
rdv1.label12.Font.Color := clwhite; rdv1.label12.Transparent := false; rdv1.label12.Color := clblack;
end ;

if jw=2 then begin
rdv1.label13.Font.Color := clwhite;rdv1.label13.Transparent := false; rdv1.label13.Color := clblack;
end ;

if jw=3 then begin
rdv1.label14.Font.Color := clwhite; rdv1.label14.Transparent := false; rdv1.label14.Color := clblack;
end ;

if jW=4 then begin
rdv1.label15.Font.Color := clwhite; rdv1.label15.Transparent := false;rdv1.label15.Color := clblack;
end;

if jw=5 then begin
rdv1.label16.Font.Color := clwhite; rdv1.label16.Transparent := false; rdv1.label16.Color := clblack;
end;

if jw=6 then begin
rdv1.label17.Font.Color := clwhite; rdv1.label17.Transparent := false; rdv1.label17.Color := clblack;
end ;

if jw=7 then begin
rdv1.label18.Font.Color := clwhite;rdv1.label18.Transparent := false; rdv1.label18.Color := clblack;
end; end; end;



procedure affectiondesjours(d:string) ;

begin
begin
testj(d);
y:= (datetostr(rdv1.MonthCalendar1.Date)) ;
//------------1-------SAMEDI
if jw=1 then
begin
with rdv1 Do
begin
label14.Font.Color := clblack;label14.Transparent := true; label12.Caption := inttostr(dayof(strtodate(y)+0));
label13.Caption := inttostr(dayof(strtodate(y)+1));label14.Caption := inttostr(dayof(strtodate(y)+2));
label15.Caption := inttostr(dayof(strtodate(y)+3)); label16.Caption := inttostr(dayof(strtodate(y)+4));
label17.Caption := inttostr(dayof(strtodate(y)+5)); label18.Caption := inttostr(dayof(strtodate(y)+6));
dbgrid1.SetFocus ;
end;
end;

//------------2-------DIMANCHE
if jw=2 then
begin
with rdv1 Do
begin
label14.Font.Color := clblack; label14.Transparent := true; label12.Caption := inttostr(dayof(strtodate(y)-1));
label13.Caption := inttostr(dayof(strtodate(y)+0)); label14.Caption := inttostr(dayof(strtodate(y)+1));
label15.Caption := inttostr(dayof(strtodate(y)+2)); label16.Caption := inttostr(dayof(strtodate(y)+3));
label17.Caption := inttostr(dayof(strtodate(y)+4)); label18.Caption := inttostr(dayof(strtodate(y)+5));
dbgrid2.SetFocus ;
end; end;

//------------3-------Lundi
if jw=3 then
begin
with rdv1 Do
begin
label14.Font.Color := clblack;label14.Transparent := true;label12.Caption := inttostr(dayof(strtodate(y)-2));
label13.Caption := inttostr(dayof(strtodate(y)-1)); label14.Caption := inttostr(dayof(strtodate(y)+0));
label15.Caption := inttostr(dayof(strtodate(y)+1)); label16.Caption := inttostr(dayof(strtodate(y)+2));
label17.Caption := inttostr(dayof(strtodate(y)+3)); label18.Caption := inttostr(dayof(strtodate(y)+4));
dbgrid3.SetFocus ;
end;
end;

//------------4-------Mardi
if jw=4 then
begin
with rdv1 Do
begin
label14.Font.Color := clblack;label14.Transparent := true; label12.Caption := inttostr(dayof(strtodate(y)-3));
label13.Caption := inttostr(dayof(strtodate(y)-2)); label14.Caption := inttostr(dayof(strtodate(y)-1));
label15.Caption := inttostr(dayof(strtodate(y)+0)); label16.Caption := inttostr(dayof(strtodate(y)+1));
label17.Caption := inttostr(dayof(strtodate(y)+2)); label18.Caption := inttostr(dayof(strtodate(y)+3));
dbgrid4.SetFocus ;
end;
end;
//------------5-------Mercredi
if jw=5 then
begin
with rdv1 Do
begin
label14.Font.Color := clblack;label14.Transparent := true;label12.Caption := inttostr(dayof(strtodate(y)-4));
label13.Caption := inttostr(dayof(strtodate(y)-3));label14.Caption := inttostr(dayof(strtodate(y)-2));
label15.Caption := inttostr(dayof(strtodate(y)-1));label16.Caption := inttostr(dayof(strtodate(y)+0));
label17.Caption := inttostr(dayof(strtodate(y)+1)); label18.Caption := inttostr(dayof(strtodate(y)+2));
dbgrid5.SetFocus ;
end;
end;
//------------6-------jeudi
if jw=6 then
begin
with rdv1 Do
begin
label14.Font.Color := clblack; label14.Transparent := true;label12.Caption := inttostr(dayof(strtodate(y)-5));
label13.Caption := inttostr(dayof(strtodate(y)-4)); label14.Caption := inttostr(dayof(strtodate(y)-3));
label15.Caption := inttostr(dayof(strtodate(y)-2)); label16.Caption := inttostr(dayof(strtodate(y)-1));
label17.Caption := inttostr(dayof(strtodate(y)+0)); label18.Caption := inttostr(dayof(strtodate(y)+1));
dbgrid6.SetFocus ;
end;
end;
//------------7-------Vendredi
if jw=7 then
begin
with rdv1 Do
begin
label14.Font.Color := clblack; label14.Transparent := true; label12.Caption := inttostr(dayof(strtodate(y)-6));
label13.Caption := inttostr(dayof(strtodate(y)-5));label14.Caption := inttostr(dayof(strtodate(y)-4));
label15.Caption := inttostr(dayof(strtodate(y)-3)); label16.Caption := inttostr(dayof(strtodate(y)-2));
label17.Caption := inttostr(dayof(strtodate(y)-1)); label18.Caption := inttostr(dayof(strtodate(y)+0));
dbgrid7.SetFocus ;
end; end; end; end;
Bacterius Messages postés 3792 Date d'inscription samedi 22 décembre 2007 Statut Membre Dernière intervention 3 juin 2016 10
25 avril 2009 à 17:38
Je crois qu'il est possible de choisir le jour de début de la semaine quelque part dans DateUtils (on peut le faire à l'initialisation du projet, par exemple, on choisit la norme qu'on veut adopter).

Cordialement, Bacterius !
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
25 avril 2009 à 13:03
Remarque: WeekOfTheYear définit la semaine d'après la norme ISO 8601. La semaine commence le lundi et s'achève le dimanche.
sp40 Messages postés 1276 Date d'inscription mardi 28 octobre 2003 Statut Contributeur Dernière intervention 3 juillet 2015 15
25 avril 2009 à 08:58
Bonjour aussi fOxi ;)

Merci pour les suggestions, je les intégre la semaine prochaine (je suis sur fedora le week end...)
Concernant le DateUtils, je me rappelle plus trop mais il me semble que le problème c'est que le weeknumber considère que le premier jour de la semaine est le dimanche, alors que le IsoWeekNumber de la jcl est bien le lundi. Je vérifierai ça et verrai si je peux le corriger (au pire, je récupèrerai la fonction).

bon week end
Simon
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
24 avril 2009 à 19:18
vire l'unité JVCL! utilise l'unité DateUtils (natif)!

tu peux ajouter en plus :

type
TDateTimePicker = class(ComCtrls.TDateTimePicker)
private
public
function DateLong : string;
function DateShort : string;
function DayLongNameStr : string;
function DayShortNameStr : string;
function MonthLongNameStr : string;
function MonthShortNameStr : string;
function DayOfWeek : integer;
function DayOfYear : integer;
function DayInMonth : integer;
function DayInYear : integer;
function WeekOfMonth : integer;
function WeekOfYear : integer;
function WeekInYear : integer;
function IsLeapYear : boolean;
end;

{ TDateTimePicker }

function TDateTimePicker.DateLong: string;
begin
DateTimeToString(result, 'dddddd', Self.DateTime);
end;

function TDateTimePicker.DateShort: string;
begin
DateTimeToString(result, 'ddddd', Self.DateTime);
end;

function TDateTimePicker.DayInMonth: integer;
begin
result := DaysInMonth(Self.DateTime);
end;

function TDateTimePicker.DayInYear: integer;
begin
result := DaysInYear(Self.DateTime);
end;

function TDateTimePicker.DayLongNameStr: string;
begin
DateTimeToString(result, 'dddd', Self.DateTime);
end;

function TDateTimePicker.DayOfYear: integer;
begin
result := DayOfTheYear(Self.DateTime);
end;

function TDateTimePicker.DayOfWeek: integer;
begin
result := DayOfTheWeek(Self.DateTime);
end;

function TDateTimePicker.DayShortNameStr: string;
begin
DateTimeToString(result, 'ddd', Self.DateTime);
end;

function TDateTimePicker.IsLeapYear: boolean;
begin
result := IsInLeapYear(Self.DateTime);
end;

function TDateTimePicker.MonthLongNameStr: string;
begin
DateTimeToString(result, 'mmmm', Self.DateTime);
end;

function TDateTimePicker.MonthShortNameStr: string;
begin
DateTimeToString(result, 'mmm', Self.DateTime);
end;

function TDateTimePicker.WeekInYear: integer;
begin
result := WeeksInYear(Self.DateTime);
end;

function TDateTimePicker.WeekOfMonth: integer;
begin
result := WeekOfTheMonth(Self.DateTime);
end;

function TDateTimePicker.WeekOfYear: integer;
begin
result := WeekOfTheYear(Self.DateTime);
end;
Rejoignez-nous