/
Holiday.cs
122 lines (105 loc) · 4.11 KB
/
Holiday.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//===============================================================================================================
// System : Personal Data Interchange Classes
// File : Holidays.cs
// Author : Eric Woodruff (Eric@EWoodruff.us)
// Updated : 11/22/2021
// Note : Copyright 2003-2021, Eric Woodruff, All rights reserved
//
// This file contains an abstract base classes used to automatically calculate holiday dates
//
// This code is published under the Microsoft Public License (Ms-PL). A copy of the license should be
// distributed with the code and can be found at the project website: https://github.com/EWSoftware/PDI.
// This notice, the author's name, and all copyright notices must remain intact in all applications,
// documentation, and source files.
//
// Date Who Comments
// ==============================================================================================================
// 07/10/2003 EFW Created the code
//===============================================================================================================
using System;
using System.Xml.Serialization;
namespace EWSoftware.PDI
{
/// <summary>
/// This abstract base class defines the core features of a holiday object
/// </summary>
[Serializable]
public abstract class Holiday : ICloneable
{
#region Private data members
//=====================================================================
private int holidayMonth;
#endregion
#region Properties
//=====================================================================
/// <summary>
/// This sets or gets the month used for the holiday
/// </summary>
/// <exception cref="System.ArgumentOutOfRangeException">An exception will be thrown if the month is not
/// between 1 and 12.
/// </exception>
[XmlAttribute]
public virtual int Month
{
get => holidayMonth;
set
{
if(value < 1 || value > 12)
throw new ArgumentOutOfRangeException(nameof(value), value, LR.GetString("ExHolBadMonthValue"));
holidayMonth = value;
}
}
/// <summary>
/// This sets or gets a description for the holiday
/// </summary>
[XmlText]
public string Description { get; set; }
/// <summary>
/// The minimum year for the holiday
/// </summary>
/// <value>If not set, the default is 1</value>
[XmlAttribute]
public int MinimumYear { get; set; }
/// <summary>
/// The maximum year for the holiday
/// </summary>
/// <value>If not set, the default is 9999</value>
[XmlAttribute]
public int MaximumYear { get; set; }
#endregion
#region Constructor
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
protected Holiday()
{
this.MinimumYear = 1;
this.MaximumYear = 9999;
}
#endregion
#region Methods
//=====================================================================
/// <summary>
/// This must be overridden to clone a holiday object
/// </summary>
/// <returns>A clone of the object</returns>
public abstract object Clone();
/// <summary>
/// Convert the instance to a <see cref="DateTime" /> object based on its settings and the passed year
/// value.
/// </summary>
/// <param name="year">The year in which the holiday occurs</param>
/// <returns>Returns a <see cref="DateTime" /> object that represents the holiday date</returns>
public abstract DateTime ToDateTime(int year);
/// <summary>
/// Convert the holiday instance to its string description
/// </summary>
/// <returns>Returns the description of the holiday</returns>
public override string ToString()
{
return this.Description;
}
#endregion
}
}