forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.cs
More file actions
55 lines (44 loc) · 1.04 KB
/
Date.cs
File metadata and controls
55 lines (44 loc) · 1.04 KB
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
using System;
namespace JavaScriptEngineSwitcher.Tests.Interop
{
public struct Date
{
private static readonly int[] _cumulativeDays = [0, 31, 59, 90, 120, 151, 181,
212, 243, 273, 304, 334];
public int Year;
public int Month;
public int Day;
public static Date Today
{
get
{
DateTime currentDateTime = DateTime.Today;
var currentDate = new Date(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day);
return currentDate;
}
}
public Date(int year, int month, int day)
{
Year = year;
Month = month;
Day = day;
}
public static bool IsLeapYear(int year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
public int GetDayOfYear()
{
return _cumulativeDays[Month - 1] +
Day +
(Month > 2 && IsLeapYear(Year) ? 1 : 0)
;
}
public Date AddDays(double value)
{
var dateTime = new DateTime(Year, Month, Day);
DateTime newDateTime = dateTime.AddDays(value);
return new Date(newDateTime.Year, newDateTime.Month, newDateTime.Day);
}
}
}