-
Notifications
You must be signed in to change notification settings - Fork 0
/
IslamicDate.cs
78 lines (63 loc) · 2.72 KB
/
IslamicDate.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
using System;
using KCalendar.Core.Contract;
using KCalendar.Core.Culture;
namespace KCalendar.Core
{
public class IslamicDate : Calendar
{
public IslamicDate() { }
public IslamicDate(int year, int month, int day)
: base(year, month, day)
{ }
public IslamicDate(double julianNumber)
: base(julianNumber)
{ }
public IslamicDate(ICalendar iCalendar)
: base(iCalendar)
{ }
public IslamicDate(DateTime dateTime)
: base(new GregorianDate(dateTime).JulianDay)
{ }
protected IslamicDate(int year, IMonth month, int day, int hour, int minute, int second, int millisecond) : base(year, month, day, hour, minute, second, millisecond) { }
protected IslamicDate(int year, IMonth month, int day, int hour, int minute, int second) : base(year, month, day, hour, minute, second) { }
public override double Epoch => 1948439.5;
public static ICalendar Today => new IslamicDate(DateTime.Now);
public override int DayOfYear => (int)(JulianDay - DateToJulian(new IslamicDate(Year, 1, 1)));
public override ICalendarLeap LeapAlgorithm { get; set; }
public override ICalendar JulianToDate(double julianNumber)
{
double year;
double month;
double day;
julianNumber = Math.Floor(julianNumber) + 0.5;
year = Math.Floor(((30 * (julianNumber - Epoch)) + 10646) / 10631);
month = Math.Min(12, Math.Ceiling((julianNumber - (29 + DateToJulian(new IslamicDate((int)year, 1, 1)))) / 29.5) + 1);
day = (julianNumber - DateToJulian(new IslamicDate((int)year, (int)month, 1))) + 1;
Year = (int)year;
Month = CalendarCulture.GetMonth((int)month);
Day = (int)day;
return new IslamicDate(Year, Month, Day);
}
public override CalendarCulture CalendarCulture { get; set; }
public override double DateToJulian(ICalendar calendarDate)
{
return (calendarDate.Day +
Math.Ceiling(29.5 * (calendarDate.Month.Index - 1))
+ (calendarDate.Year - 1) * 354
+ Math.Floor(d: (3 + (11 * calendarDate.Year)) / 30.0) + Epoch) - 1; ;
}
protected override void Init()
{
CalendarCulture = new IslamicCalendarCulture();
LeapAlgorithm = new IslamicLeap();
}
public static explicit operator IslamicDate(string date)
{
return (IslamicDate)Parse(date, new IslamicDate());
}
public static explicit operator IslamicDate(double jDay)
{
return new IslamicDate(jDay);
}
}
}