From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。

---
 HotelPms.Share.Windows/Util/JapaneseDateTime.cs |  182 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 182 insertions(+), 0 deletions(-)

diff --git a/HotelPms.Share.Windows/Util/JapaneseDateTime.cs b/HotelPms.Share.Windows/Util/JapaneseDateTime.cs
new file mode 100644
index 0000000..c7d45d8
--- /dev/null
+++ b/HotelPms.Share.Windows/Util/JapaneseDateTime.cs
@@ -0,0 +1,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;
+            }
+        }
+    }
+}

--
Gitblit v1.10.0