Addintion des heures et minutes de travail

Signaler
Messages postés
68
Date d'inscription
jeudi 1 juillet 2004
Statut
Membre
Dernière intervention
23 juin 2011
-
Messages postés
4202
Date d'inscription
samedi 16 octobre 2004
Statut
Modérateur
Dernière intervention
13 juin 2020
-
bonjour,


comment peut on additionner des heures et minutes de travail et exprimer un pourcentage de ce nombre par rapport a la duree maximale du nombre d'heures de travail?.
Par  exemple :
1er jour : duree travail = 7:45
2e  jour : duree travail = 9:00
3e jour  : duree travail = 8:10
4e jour  : duree travai l= 10:50
 total                          =34:45
duree de travail par semaine = 50H
%= (34:45 / 50) * 100 
Comment programmer tous ca?
merci   


 

1 réponse

Messages postés
4202
Date d'inscription
samedi 16 octobre 2004
Statut
Modérateur
Dernière intervention
13 juin 2020
37
Unité WorkWeek :


unit WorkWeek;

interface

uses Windows, SysUtils, Classes, Controls;

type
  TDays = (dMonday,
           dTuesday,
           dWednesday,
           dThursday,
           dFriday,
           dSaturday,
           dSunday);

  TWorkWeek = class
  private
    fWeek : array[TDays] of LongWord;
    fHMAX : LongWord;
    fPRAT : Single;
    function GetWeekMaxHours: LongWord;
    function GetDayTimeLW(Day: TDays): LongWord;
    function GetDayTime(Day: TDays): TDateTime;
    function GetDayTimeStr(Day: TDays): String;
    function GetWeekSupHoursLW: LongWord;
    function GetWeekSupHours: TDateTime;
    function GetWeekSupHoursStr: String;
    function GetWeekTotalTimeLW: LongWord;
    function GetWeekTotalTime: TDateTime;
    function GetWeekTotalTimeStr: String;
    function GetWeekTotalTimePercent: single;
    function GetWeekTotalTimePercentStr: String;
    procedure SetDayTime(Day: TDays; const Value: TDateTime);
    procedure SetDayTimeLW(Day: TDays; const Value: LongWord);
    procedure SetDayTimeStr(Day: TDays; const Value: String);
    procedure SetWeekMaxHours(const Value: LongWord);
  public
    { Heures max par semaine }
    property WeekMaxHours           : LongWord  read GetWeekMaxHours write SetWeekMaxHours default 50;
    { Temps par jours (LW = temps en minutes)}
    property DayTimeLW[Day: TDays]  : LongWord  read GetDayTimeLW    write SetDayTimeLW;
    property DayTime[Day: TDays]    : TDateTime read GetDayTime      write SetDayTime;
    property DayTimeStr[Day: TDays] : String    read GetDayTimeStr   write SetDayTimeStr;
    { Heures totales de la semaine (LW = temps en minutes)}
    property WeekTotalTimeLW        : LongWord  read GetWeekTotalTimeLW;
    property WeekTotalTime          : TDateTime read GetWeekTotalTime;
    property WeekTotalTimeStr       : String    read GetWeekTotalTimeStr;
    { Heures totales en % par semaine }
    property WeekTotalTimePercent   : single    read GetWeekTotalTimePercent;
    property WeekTotalTimePercentStr: String    read GetWeekTotalTimePercentStr;
    { Heures supplementaires (LW = temps en minutes)}
    property WeekSupHoursLW         : LongWord  read GetWeekSupHoursLW;
    property WeekSupHours           : TDateTime read GetWeekSupHours;
    property WeekSupHoursStr        : String    read GetWeekSupHoursStr;
  public
    { Mise a zero des compteurs de temps de la semaine }
    procedure Clear;
    { Construction }
    constructor Create;
  end;

implementation

{ TWorkWeek }

procedure TWorkWeek.Clear;
var I : TDays;
begin
  for I := Low(TDays) to High(TDays) do
    fWeek[I] := 0;
end;

constructor TWorkWeek.Create;
begin
  Inherited;
  Clear;
  SetWeekMaxHours(50);
end;

function TWorkWeek.GetDayTime(Day: TDays): TDateTime;
var H,M,S,Z : word;
begin
  H := fWeek[Day] div 60;
  M := fWeek[Day] mod 60;
  S := 0;
  Z := 0;
  Result := EncodeTime(H, M, S ,Z);
end;

function TWorkWeek.GetDayTimeLW(Day: TDays): LongWord;
begin
  result := fWeek[Day];
end;

function TWorkWeek.GetDayTimeStr(Day: TDays): String;
begin
  result := format('%d:%.2d',[fWeek[Day] div 60, fWeek[Day] mod 60]);
end;

function TWorkWeek.GetWeekMaxHours: LongWord;
begin
  result := fHMAX div 60;
end;

function TWorkWeek.GetWeekSupHours: TDateTime;
var H, M, S, Z: word;
    HS : LongWord;
begin
  HS := GetWeekSupHoursLW;
  H := HS div 60;
  M := HS mod 60;
  S := 0;
  Z := 0;
  result := EncodeTime(H,M,S,Z);
end;

function TWorkWeek.GetWeekSupHoursLW: LongWord;
begin
  if GetWeekTotalTimeLW > fHMAX then
    result := fHMAX - GetWeekTotalTimeLW
  else
    result := 0;
end;

function TWorkWeek.GetWeekSupHoursStr: String;
var HS : LongWord;
begin
  HS := GetWeekSupHoursLW;
  result := format('%d:%.2d',[HS div 60, HS mod 60]);
end;

function TWorkWeek.GetWeekTotalTime: TDateTime;
var HS : LongWord;
    H,M,S,Z: word;
begin
  HS := GetWeekTotalTimeLW;
  H := HS div 60;
  M := HS mod 60;
  S := 0;
  Z := 0;
  result := EncodeTime(H,M,S,Z);
end;

function TWorkWeek.GetWeekTotalTimeLW: LongWord;
begin
  result := fWeek[dMonday]+
            fWeek[dTuesday]+
            fWeek[dWednesday]+
            fWeek[dThursday]+
            fWeek[dFriday]+
            fWeek[dSaturday]+
            fWeek[dSunday];
end;

function TWorkWeek.GetWeekTotalTimeStr: String;
var HS : LongWord;
begin
  HS := GetWeekTotalTimeLW;
  result := format('%d:%.2d',[HS div 60, HS mod 60]);
end;

function TWorkWeek.GetWeekTotalTimePercent: single;
begin
  result := fPRAT * GetWeekTotalTimeLW;
end;

function TWorkWeek.GetWeekTotalTimePercentStr: String;
begin
  result := format('%.2f%%',[GetWeekTotalTimePercent]);
end;

procedure TWorkWeek.SetDayTime(Day: TDays; const Value: TDateTime);
var H,M,S,Z: word;
begin
  DecodeTime(Value, H,M,S,Z);
  fWeek[Day] := M + H*60;
end;

procedure TWorkWeek.SetDayTimeLW(Day: TDays; const Value: LongWord);
begin
  fWeek[Day] := Value;
end;

procedure TWorkWeek.SetDayTimeStr(Day: TDays; const Value: String);
var H,M,S,Z : word;
begin
  DecodeTime(StrToTime(Value), H,M,S,Z);
  fWeek[Day] := M + H*60;
end;

procedure TWorkWeek.SetWeekMaxHours(const Value: LongWord);
begin
  fHMAX := Value * 60;
  fPRAT := 100 / fHMAX;
end;

end.


Exemple d'utilisation :

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm4 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

uses WorkWeek;

{ TForm4 }

var
  Week : TWorkWeek;

procedure TForm4.FormCreate(Sender: TObject);
begin
  Week := TWorkWeek.Create;
  Week.DayTimeStr[dMonday]   := '08:00';
  Week.DayTimeStr[dTuesday]  := '08:00';
  Week.DayTimeStr[dWednesday]:= '08:00';
  Week.DayTimeStr[dThursday] := '08:00';
  Week.DayTimeStr[dFriday]   := '08:00';

  caption := Week.WeekTotalTimePercentStr;
end;

procedure TForm4.FormDestroy(Sender: TObject);
begin
  Week.Free;
end;

end.