ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace HotelPms.Share.Windows.Util
{
    public class JapaneseDateTime
    {
        private int year, month, dayOfMonth;
        private bool isLeap;
        private DateTime time;
        //System.Globalization.ChineseLunisolarCalendar cc;
        System.Globalization.JapaneseLunisolarCalendar cc;
        private static string[] RokuyouList = new string[] { "大安", "赤口", "先勝", "友引", "先負", "仏滅" };
 
        /// <summary>
        /// 旧暦年
        /// </summary>
        public int Year
        {
            get { return year; }
        }
 
        /// <summary>
        /// 旧暦月
        /// </summary>
        public int Month
        {
            get { return month; }
        }
 
        /// <summary>
        /// 新暦時間
        /// </summary>
        public DateTime NewTime
        {
            get { return time; }
        }
 
        /// <summary>
        /// 旧暦時間
        /// </summary>
        public DateTime OldTime
        {
            get { return new DateTime(year, month, dayOfMonth); }
        }
 
        /// <summary>
        /// 旧暦日
        /// </summary>
        public int DayOfMonth
        {
            get { return dayOfMonth; }
        }
 
        /// <summary>
        /// 閏月かどうか
        /// </summary>
        public bool IsLeap
        {
            get { return isLeap; }
        }
 
        /// <summary>
        /// 指定日付で旧暦を変換する
        /// </summary>
        /// <param name="time"></param>
        public JapaneseDateTime(DateTime time)
        {
            //cc = new System.Globalization.ChineseLunisolarCalendar();
            cc = new System.Globalization.JapaneseLunisolarCalendar();
 
            if (time > cc.MaxSupportedDateTime || time < cc.MinSupportedDateTime)
                throw new Exception("Out Of Range :" + cc.MinSupportedDateTime.ToShortDateString() + "~" + cc.MaxSupportedDateTime.ToShortDateString());
            year = cc.GetYear(time);
            month = cc.GetMonth(time);
            dayOfMonth = cc.GetDayOfMonth(time);
            isLeap = cc.IsLeapMonth(year, month);
            if (cc.IsLeapYear(year) && month >= cc.GetLeapMonth(year)) { month -= 1; }
            this.time = time;
        }
 
        public static JapaneseDateTime Now
        {
            get { return new JapaneseDateTime(DateTime.Now); }
        }
 
        public JapaneseDateTime(int Year, int Month, int DayOfMonth, bool IsLeap)
        {
            if (Year >= cc.MaxSupportedDateTime.Year || Year <= cc.MinSupportedDateTime.Year)
                throw new Exception("Out Of Range ::" + cc.MinSupportedDateTime.ToShortDateString() + "~" + cc.MaxSupportedDateTime.ToShortDateString());
 
            if (Month < 1 || Month > 12)
                throw new Exception("日付が不正です。");
            //cc = new System.Globalization.ChineseLunisolarCalendar();
            cc = new System.Globalization.JapaneseLunisolarCalendar();
 
            if (cc.GetLeapMonth(Year) != Month && IsLeap)
                throw new Exception("GetLeapMonth Error");
            if (cc.GetDaysInMonth(Year, IsLeap ? Month + 1 : Month) < DayOfMonth || DayOfMonth < 1)
                throw new Exception("Day Error");
            year = Year;
            month = Month;
            dayOfMonth = DayOfMonth;
            isLeap = IsLeap;
            time = DateTime.Now;
        }
 
        /// <summary>
        /// 旧暦⇒新暦
        /// </summary>
        /// <returns></returns>
        public DateTime ToDateTime()
        {
            return cc.ToDateTime(year, isLeap ? month + 1 : month, dayOfMonth, time.Hour, time.Minute, time.Second, time.Millisecond);
        }
 
        /// <summary>
        /// 旧暦⇒新暦
        /// </summary>
        /// <returns></returns>
        public static DateTime ToDateTime(JapaneseDateTime CnTime)
        {
            return CnTime.ToDateTime();
        }
 
        /// <summary>
        /// 新暦⇒旧暦
        /// </summary>
        /// <returns></returns>
        public static JapaneseDateTime ToJapaneseDateTime(DateTime Time)
        {
            return new JapaneseDateTime(Time);
        }
 
        /// <summary>
        /// 新暦⇒旧暦
        /// </summary>
        /// <returns></returns>
        public static string ToJapaneseDateString(DateTime Time)
        {
            return ToJapaneseDateString(Time, "yyyy/MM/dd");
        }
 
        /// <summary>
        /// 新暦⇒旧暦
        /// </summary>
        /// <returns></returns>
        public static string ToJapaneseDateString(DateTime Time, string format)
        {
            try
            {
                JapaneseDateTime jpDate = new JapaneseDateTime(Time);
                return jpDate.OldTime.ToString(format);
            }
            catch
            {
                return string.Empty;
            }
        }
 
        /// <summary>
        /// 新暦⇒六曜
        /// </summary>
        /// <returns></returns>
        public static string ToRokuyou(DateTime Time)
        {
            try
            {
                JapaneseDateTime jpDate = new JapaneseDateTime(Time);
                int index = (jpDate.Month + jpDate.DayOfMonth) % 6;
                return RokuyouList[index];
            }
            catch
            {
                return string.Empty;
            }
        }
    }
}