You've already forked lazarus-ccr
tvplanit: Refactor calculation of holidays in fulldemo
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8386 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -4,12 +4,12 @@ object MainForm: TMainForm
|
|||||||
Top = 134
|
Top = 134
|
||||||
Width = 959
|
Width = 959
|
||||||
Caption = 'Turbo Power VisualPlanIt Demo'
|
Caption = 'Turbo Power VisualPlanIt Demo'
|
||||||
ClientHeight = 576
|
ClientHeight = 596
|
||||||
ClientWidth = 959
|
ClientWidth = 959
|
||||||
Menu = MainMenu1
|
Menu = MainMenu1
|
||||||
OnCloseQuery = FormCloseQuery
|
OnCloseQuery = FormCloseQuery
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
LCLVersion = '2.3.0.0'
|
OnDestroy = FormDestroy
|
||||||
object Panel1: TPanel
|
object Panel1: TPanel
|
||||||
Left = 125
|
Left = 125
|
||||||
Height = 596
|
Height = 596
|
||||||
@@ -81,31 +81,21 @@ object MainForm: TMainForm
|
|||||||
Width = 357
|
Width = 357
|
||||||
ShowHint = True
|
ShowHint = True
|
||||||
ControlLink = VpControlLink1
|
ControlLink = VpControlLink1
|
||||||
Color = clWindow
|
|
||||||
ParentShowHint = False
|
ParentShowHint = False
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
TabStop = True
|
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
DateLabelFormat = 'mmmm yyyy'
|
|
||||||
DayHeadAttributes.Color = clBtnFace
|
DayHeadAttributes.Color = clBtnFace
|
||||||
DayNameStyle = dsShort
|
|
||||||
DrawingStyle = dsFlat
|
DrawingStyle = dsFlat
|
||||||
EventDayStyle = [fsItalic]
|
EventDayStyle = [fsItalic]
|
||||||
HeadAttributes.Font.Height = -13
|
HeadAttributes.Font.Height = -13
|
||||||
HeadAttributes.Font.Style = [fsItalic]
|
HeadAttributes.Font.Style = [fsItalic]
|
||||||
HeadAttributes.Color = clBtnFace
|
HeadAttributes.Color = clBtnFace
|
||||||
HolidayAttributes.Font.Color = clBlack
|
HolidayAttributes.Font.Color = clBlack
|
||||||
KBNavigation = True
|
|
||||||
SelectedDayColor = clRed
|
|
||||||
ShowEvents = True
|
|
||||||
ShowEventTime = False
|
|
||||||
TimeFormat = tf12Hour
|
|
||||||
TodayAttributes.Font.Color = clBlue
|
TodayAttributes.Font.Color = clBlue
|
||||||
TodayAttributes.Color = 16761024
|
TodayAttributes.Color = 16761024
|
||||||
TodayAttributes.BorderPen.Color = clBlue
|
TodayAttributes.BorderPen.Color = clBlue
|
||||||
TodayAttributes.BorderPen.Width = 3
|
TodayAttributes.BorderPen.Width = 3
|
||||||
WeekendAttributes.Font.Color = clBlack
|
WeekendAttributes.Font.Color = clBlack
|
||||||
WeekStartsOn = dtSunday
|
|
||||||
OnHoliday = VpHoliday
|
OnHoliday = VpHoliday
|
||||||
end
|
end
|
||||||
object Splitter2: TSplitter
|
object Splitter2: TSplitter
|
||||||
@@ -124,13 +114,10 @@ object MainForm: TMainForm
|
|||||||
Width = 357
|
Width = 357
|
||||||
ShowHint = True
|
ShowHint = True
|
||||||
ControlLink = VpControlLink1
|
ControlLink = VpControlLink1
|
||||||
Color = clWindow
|
|
||||||
Font.Height = -12
|
Font.Height = -12
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
ParentShowHint = False
|
ParentShowHint = False
|
||||||
Align = alClient
|
Align = alClient
|
||||||
ReadOnly = False
|
|
||||||
TabStop = True
|
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
AllDayEventAttributes.BackgroundColor = clBtnShadow
|
AllDayEventAttributes.BackgroundColor = clBtnShadow
|
||||||
AllDayEventAttributes.EventBorderColor = cl3DDkShadow
|
AllDayEventAttributes.EventBorderColor = cl3DDkShadow
|
||||||
@@ -191,13 +178,8 @@ object MainForm: TMainForm
|
|||||||
001C000000C6FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF000000
|
001C000000C6FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF000000
|
||||||
005500000038FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00
|
005500000038FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00
|
||||||
}
|
}
|
||||||
ShowResourceName = True
|
|
||||||
LineColor = clGray
|
LineColor = clGray
|
||||||
GutterWidth = 5
|
GutterWidth = 5
|
||||||
DateLabelFormat = 'dddddd'
|
|
||||||
Granularity = gr30Min
|
|
||||||
DefaultTopHour = h_07
|
|
||||||
TimeFormat = tf12Hour
|
|
||||||
WrapStyle = wsNoFlow
|
WrapStyle = wsNoFlow
|
||||||
OnHoliday = VpHoliday
|
OnHoliday = VpHoliday
|
||||||
end
|
end
|
||||||
@@ -306,7 +288,6 @@ object MainForm: TMainForm
|
|||||||
Width = 472
|
Width = 472
|
||||||
ShowHint = True
|
ShowHint = True
|
||||||
ControlLink = VpControlLink1
|
ControlLink = VpControlLink1
|
||||||
Color = clWindow
|
|
||||||
Font.Height = -12
|
Font.Height = -12
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
ParentShowHint = False
|
ParentShowHint = False
|
||||||
@@ -316,9 +297,7 @@ object MainForm: TMainForm
|
|||||||
AllDayEventAttributes.Font.Height = -12
|
AllDayEventAttributes.Font.Height = -12
|
||||||
DateLabelFormat = 'dddd, mmmm dd, yyyy'
|
DateLabelFormat = 'dddd, mmmm dd, yyyy'
|
||||||
DayHeadAttributes.Color = clBtnFace
|
DayHeadAttributes.Color = clBtnFace
|
||||||
DayHeadAttributes.DateFormat = 'dddd mmmm, dd'
|
|
||||||
DayHeadAttributes.Font.Height = -13
|
DayHeadAttributes.Font.Height = -13
|
||||||
DayHeadAttributes.Bordered = True
|
|
||||||
DrawingStyle = dsFlat
|
DrawingStyle = dsFlat
|
||||||
EventFont.Height = -12
|
EventFont.Height = -12
|
||||||
HeadAttributes.Font.Height = -13
|
HeadAttributes.Font.Height = -13
|
||||||
@@ -326,11 +305,8 @@ object MainForm: TMainForm
|
|||||||
HeadAttributes.Color = clBtnFace
|
HeadAttributes.Color = clBtnFace
|
||||||
LineColor = clGray
|
LineColor = clGray
|
||||||
Layout = wvlHorizontal
|
Layout = wvlHorizontal
|
||||||
TimeFormat = tf12Hour
|
|
||||||
ShowEventTime = True
|
|
||||||
WeekStartsOn = dtMonday
|
WeekStartsOn = dtMonday
|
||||||
Align = alClient
|
Align = alClient
|
||||||
TabStop = True
|
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
OnHoliday = VpHoliday
|
OnHoliday = VpHoliday
|
||||||
end
|
end
|
||||||
@@ -383,12 +359,9 @@ object MainForm: TMainForm
|
|||||||
Top = 27
|
Top = 27
|
||||||
Width = 834
|
Width = 834
|
||||||
ControlLink = VpControlLink1
|
ControlLink = VpControlLink1
|
||||||
Color = clWindow
|
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
Align = alClient
|
Align = alClient
|
||||||
TabStop = True
|
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
ReadOnly = False
|
|
||||||
DisplayOptions.CheckBGColor = clWindow
|
DisplayOptions.CheckBGColor = clWindow
|
||||||
DisplayOptions.CheckColor = cl3DDkShadow
|
DisplayOptions.CheckColor = cl3DDkShadow
|
||||||
DisplayOptions.CheckStyle = csCheck
|
DisplayOptions.CheckStyle = csCheck
|
||||||
@@ -404,7 +377,6 @@ object MainForm: TMainForm
|
|||||||
TaskHeadAttributes.Color = clSilver
|
TaskHeadAttributes.Color = clSilver
|
||||||
TaskHeadAttributes.Font.Style = [fsItalic]
|
TaskHeadAttributes.Font.Style = [fsItalic]
|
||||||
DrawingStyle = dsFlat
|
DrawingStyle = dsFlat
|
||||||
ShowResourceName = True
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
object Contacts: TPage
|
object Contacts: TPage
|
||||||
@@ -427,14 +399,10 @@ object MainForm: TMainForm
|
|||||||
Top = 0
|
Top = 0
|
||||||
Width = 794
|
Width = 794
|
||||||
ControlLink = VpControlLink1
|
ControlLink = VpControlLink1
|
||||||
Color = clWindow
|
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
Align = alClient
|
Align = alClient
|
||||||
TabStop = True
|
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
AllowInPlaceEditing = True
|
|
||||||
BarWidth = 1
|
BarWidth = 1
|
||||||
BarColor = clSilver
|
|
||||||
ColumnWidth = 200
|
ColumnWidth = 200
|
||||||
ContactHeadAttributes.Color = clSilver
|
ContactHeadAttributes.Color = clSilver
|
||||||
ContactHeadAttributes.Bordered = True
|
ContactHeadAttributes.Bordered = True
|
||||||
|
@@ -9,13 +9,18 @@ uses
|
|||||||
clocale,
|
clocale,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Classes, SysUtils, FileUtil, PrintersDlgs, Forms, Controls, Graphics, Dialogs,
|
Classes, SysUtils, FileUtil, PrintersDlgs, Forms, Controls, Graphics, Dialogs,
|
||||||
ExtCtrls, StdCtrls, ComCtrls, LCLTranslator, Menus, Types, LCLVersion,
|
ExtCtrls, StdCtrls, ComCtrls, LCLTranslator, Menus, Types, LCLVersion, Contnrs,
|
||||||
CheckLst, VpBaseDS, VpDayView, VpWeekView, VpTaskList, VpAbout, VpContactGrid,
|
CheckLst, VpBaseDS, VpDayView, VpWeekView, VpTaskList, VpAbout, VpContactGrid,
|
||||||
VpMonthView, VpResEditDlg, VpContactButtons, VpNavBar, VpData, VpPrtPrvDlg,
|
VpMonthView, VpResEditDlg, VpContactButtons, VpNavBar, VpData, VpPrtPrvDlg,
|
||||||
VpPrtFmtDlg, VpBase;
|
VpPrtFmtDlg, VpBase;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
THoliday = class
|
||||||
|
Name: String;
|
||||||
|
Date: TDate;
|
||||||
|
constructor Create(AName: String; ADate: TDate);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TMainForm }
|
{ TMainForm }
|
||||||
|
|
||||||
TMainForm = class(TForm)
|
TMainForm = class(TForm)
|
||||||
@@ -109,6 +114,7 @@ type
|
|||||||
procedure DaysTrackBarChange(Sender: TObject);
|
procedure DaysTrackBarChange(Sender: TObject);
|
||||||
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
|
procedure FormDestroy(Sender: TObject);
|
||||||
procedure lbOtherResourcesClickCheck(Sender: TObject);
|
procedure lbOtherResourcesClickCheck(Sender: TObject);
|
||||||
procedure MnuAboutClick(Sender: TObject);
|
procedure MnuAboutClick(Sender: TObject);
|
||||||
procedure MnuEditPrintFormatsClick(Sender: TObject);
|
procedure MnuEditPrintFormatsClick(Sender: TObject);
|
||||||
@@ -134,6 +140,9 @@ type
|
|||||||
FVisibleDays: Integer;
|
FVisibleDays: Integer;
|
||||||
FResID: Integer;
|
FResID: Integer;
|
||||||
FLanguageDir: String;
|
FLanguageDir: String;
|
||||||
|
FHolidays: TFPObjectList;
|
||||||
|
FHolidaysYear: Integer;
|
||||||
|
procedure CalcHolidays(AYear: Integer);
|
||||||
procedure ConnectHandler(Sender: TObject);
|
procedure ConnectHandler(Sender: TObject);
|
||||||
procedure CreateResourceGroup;
|
procedure CreateResourceGroup;
|
||||||
function GetlanguageDir: String;
|
function GetlanguageDir: String;
|
||||||
@@ -317,6 +326,12 @@ begin
|
|||||||
Result := dtSunday;
|
Result := dtSunday;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor THoliday.Create(AName: String; ADate: TDate);
|
||||||
|
begin
|
||||||
|
Name := AName;
|
||||||
|
Date := ADate;
|
||||||
|
end;
|
||||||
|
|
||||||
function Easter(AYear: integer): TDateTime;
|
function Easter(AYear: integer): TDateTime;
|
||||||
// Calculates the date of the Easter holiday
|
// Calculates the date of the Easter holiday
|
||||||
var
|
var
|
||||||
@@ -382,6 +397,44 @@ begin
|
|||||||
UpdateOtherResourcesList;
|
UpdateOtherResourcesList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.CalcHolidays(AYear: Integer);
|
||||||
|
var
|
||||||
|
d: TDate;
|
||||||
|
wd: Integer;
|
||||||
|
begin
|
||||||
|
FHolidays.Clear;
|
||||||
|
|
||||||
|
// New Year
|
||||||
|
FHolidays.Add(THoliday.Create('New Year', EncodeDate(AYear, 1, 1)));
|
||||||
|
|
||||||
|
// Easter & related
|
||||||
|
d := Easter(AYear);
|
||||||
|
FHolidays.Add(THoliday.Create('Good Friday', d-2));
|
||||||
|
FHolidays.Add(THoliday.Create('Easter', d));
|
||||||
|
FHolidays.Add(THoliday.Create('Whitsunday', d + 49));
|
||||||
|
|
||||||
|
// Independence day
|
||||||
|
d := EncodeDate(AYear, 7, 4);
|
||||||
|
wd := DayOfTheWeek(d);
|
||||||
|
if wd = DaySaturday then
|
||||||
|
d := d + 2
|
||||||
|
else
|
||||||
|
if wd = DaySunday then
|
||||||
|
d := d + 1;
|
||||||
|
FHolidays.Add(THoliday.Create('Indepencence Day (U.S.)', d));
|
||||||
|
|
||||||
|
// Labor Day
|
||||||
|
d := EncodeDayOfWeekInMonth(AYear, 9, 1, DayMonday); // 1st Monday in September
|
||||||
|
FHolidays.Add(THoliday.Create('Labor Day (U.S.)', d));
|
||||||
|
|
||||||
|
// Thanksgiving
|
||||||
|
d := EncodeDayOfWeekInMonth(AYear, 11, 4, DayThursday); // 4th Thursday in November
|
||||||
|
FHolidays.Add(THoliday.Create('Thanksgiving (U.S.)', d));
|
||||||
|
|
||||||
|
// Christmas
|
||||||
|
FHolidays.Add(THoliday.Create('Christmas', EncodeDate(AYear, 12, 25)));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMainForm.Cb3DChange(Sender: TObject);
|
procedure TMainForm.Cb3DChange(Sender: TObject);
|
||||||
var
|
var
|
||||||
ds: TVpDrawingStyle;
|
ds: TVpDrawingStyle;
|
||||||
@@ -521,6 +574,8 @@ procedure TMainForm.FormCreate(Sender: TObject);
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
FHolidays := TFPObjectList.Create;
|
||||||
|
|
||||||
PopulateLanguages;
|
PopulateLanguages;
|
||||||
ReadIni;
|
ReadIni;
|
||||||
|
|
||||||
@@ -574,6 +629,11 @@ begin
|
|||||||
if Components[i] is TLabel then TLabel(Components[i]).Transparent := true;
|
if Components[i] is TLabel then TLabel(Components[i]).Transparent := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.FormDestroy(Sender: TObject);
|
||||||
|
begin
|
||||||
|
FHolidays.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMainForm.lbOtherResourcesClickCheck(Sender: TObject);
|
procedure TMainForm.lbOtherResourcesClickCheck(Sender: TObject);
|
||||||
var
|
var
|
||||||
i, n: Integer;
|
i, n: Integer;
|
||||||
@@ -1183,34 +1243,23 @@ end;
|
|||||||
procedure TMainForm.VpHoliday(Sender: TObject; ADate: TDateTime;
|
procedure TMainForm.VpHoliday(Sender: TObject; ADate: TDateTime;
|
||||||
var AHolidayName: String);
|
var AHolidayName: String);
|
||||||
var
|
var
|
||||||
d,m,y: Word;
|
i: Integer;
|
||||||
tmp: Word;
|
holiday: THoliday;
|
||||||
easterDate: TDate;
|
year: Integer;
|
||||||
begin
|
begin
|
||||||
DecodeDate(ADate, y,m,d);
|
year := YearOf(ADate);
|
||||||
if (d=1) and (m=1) then
|
if year <> FHolidaysYear then
|
||||||
AHolidayName := 'New Year'
|
begin
|
||||||
else
|
FHolidaysYear := year;
|
||||||
if (d = 25) and (m = 12) then
|
CalcHolidays(year);
|
||||||
AHolidayName := 'Christmas'
|
end;
|
||||||
else
|
for i := 0 to FHolidays.Count-1 do
|
||||||
if m = 9 then begin
|
begin
|
||||||
tmp := 1;
|
holiday := THoliday(FHolidays[i]);
|
||||||
while DayOfWeek(EncodeDate(y, m, tmp)) <> 2 do inc(tmp);
|
if holiday.Date = ADate then begin
|
||||||
if tmp = d then
|
AHolidayName := holiday.Name;
|
||||||
AHolidayName := 'Labor Day (U.S.)'; // 1st Monday in September
|
exit;
|
||||||
end
|
end;
|
||||||
else begin
|
|
||||||
// Holidays depending on the date of Easter.
|
|
||||||
easterDate := Easter(y);
|
|
||||||
if ADate = easterDate - 2 then
|
|
||||||
AHolidayName := 'Good Friday'
|
|
||||||
else
|
|
||||||
if ADate = easterDate then
|
|
||||||
AHolidayName := 'Easter'
|
|
||||||
else
|
|
||||||
if ADate = easterDate + 49 then
|
|
||||||
AHolidayName := 'Whitsunday'
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user