classdef clsdate
% This program converts for date among solardate, lunardate and ganzhi-
% date from (1900,2,4) to (2099,12,31), except the conversion from gan-
% zhidate to solardate and lunardate.
%
% This Class contains
% (a) five properties:
% year; month; day; hour; isLeap;
% (b) two static methods:
% YearDays=YearInfos2YearDays_GanZhiDate();
% YearDays=YearInfos2YearDays_LunarDate();
% (c) three private methods:
% offset=LunarDate2DayOffset(obj);
% obj=DayOffset2LunarDate(obj,offset);
% obj=DayOffset2GanZhiDate(obj,offset);
% (d) five general methods:
% obj=clsdate(year,month,day,isLeap);
% obj=SolarDate2LunarDate(obj);
% obj=LunarDate2SolarDate(obj);
% obj=SolarDate2GanZhiDate(obj);
% obj=LunarDate2GanZhiDate(obj);
%
% Example:
% [yy,mm,dd]=datevec(date);
% yy=2017;mm=7;dd=30;
% clsdate(yy,mm,dd).YearInfos2YearDays_GanZhiDate();
% clsdate(yy,mm,dd).SolarDate2LunarDate
% clsdate(yy,mm,dd).SolarDate2GanZhiDate
%
% yy=2017;mm=6;dd=8;
% clsdate(yy,mm,dd,1).YearInfos2YearDays_LunarDate;
% clsdate(yy,mm,dd,1).LunarDate2SolarDate
% clsdate(yy,mm,dd,1).LunarDate2GanZhiDate
%
% Hunan University, shengzhaochen@foxmail.com, 2019.1.2
%
%
properties
year;
month;
day;
hour;
isLeap;
end
methods(Static=true)
% -----------------------------------------------------------------
function YearDays=YearInfos2YearDays_GanZhiDate()
% YearDays=YearInfos2YearDays_GanZhiDate()
% https://jieqi.51240.com/
%
YearInfos_GanZhiDate = [
% /* encoding:
% dddddddddddd
% bit% 223334332121
% ............
% month% 123456789012
%
% b_j = d means that the (j) month has (28+d)...
% days, where j = '123456789012' means ...
% '寅卯辰巳午未申酉戌亥子丑', respectively.
% */
'223334332121'; % /* 1900 */
'223343332212'; '132433332212'; '223334322212'; '223334332130'; '223343332212'; % /* 1905 */
'132343332212'; '223334322212'; '223334332130'; '223343332212'; '132343332212'; % /* 1910 */
'223334322212'; '223334332130'; '223343332211'; '223343332212'; '132433422212'; % /* 1915 */
'223334323121'; '223343332211'; '223343332212'; '132433422212'; '223334323121'; % /* 1920 */
'223343332121'; '223343332212'; '132433422212'; '223334323121'; '223343332121'; % /* 1925 */
'223343332212'; '132433422212'; '223334322221'; '223334332121'; '223343332212'; % /* 1930 */
'132433332212'; '223334322221'; '223334332121'; '223343332212'; '132343332212'; % /* 1935 */
'223334322221'; '223334332121'; '223343332212'; '132343332212'; '223334322221'; % /* 1940 */
'223334332121'; '223343332212'; '132343332212'; '222434322221'; '223334323121'; % /* 1945 */
'223343332211'; '223343332212'; '132433422221'; '223334323112'; '223343332211'; % /* 1950 */
'223343332212'; '132433422221'; '223334323112'; '223343332121'; '223343332212'; % /* 1955 */
'132433422221'; '223334323112'; '223334332121'; '223343332212'; '132433332221'; % /* 1960 */
'223334322212'; '223334332121'; '223343332212'; '132433332221'; '223334322212'; % /* 1965 */
'223334332121'; '223343332212'; '132343332221'; '223334322212'; '223334332121'; % /* 1970 */
'223343332212'; '132343332221'; '222434322212'; '223334332121'; '223343332212'; % /* 1975 */
'123343332221'; '222433422212'; '223334323121'; '223343332212'; '123343332221'; % /* 1980 */
'222433422212'; '223334323121'; '223343332211'; '223343332221'; '132433422212'; % /* 1985 */
'223334323112'; '223334332121'; '223343332221'; '132433332212'; '223334323112'; % /* 1990 */
'223334332121'; '223343332221'; '132433332212'; '223334322212'; '223334332121'; % /* 1995 */
'223343332221'; '132343332212'; '223334322212'; '223334332121'; '223343332221'; % /* 2000 */
'132343332212'; '223334322212'; '223334332121'; '223343332221'; '132343332212'; % /* 2005 */
'222433422212'; '223334332121'; '223343332221'; '123343332212'; '222433422212'; % /* 2010 */
'223334323121'; '223343332221'; '123343332212'; '222433422212'; '223334323121'; % /* 2015 */
'223343332220'; '223343332212'; '132433422212'; '223334323112'; '223334332220'; % /* 2020 */
'223343332212'; '132433332212'; '223334323112'; '223334332130'; '223343332212'; % /* 2025 */
'132343332212'; '223334322212'; '223334332130'; '223343332212'; '132343332212'; % /* 2030 */
'223334322212'; '223334332130'; '223343332212'; '132343332212'; '222433422212'; % /* 2035 */
'223334332130'; '223343332212'; '132343332212'; '222433422212'; '223334332130'; % /* 2040 */
'223343332212'; '123343332212'; '222433422212'; '223334323130'; '223343332212'; % /* 2045 */
'123343332212'; '222433422212'; '223334323130'; '223334332211'; '223343332212'; % /* 2050 */
'132433332212'; '223334323121'; '223334332211'; '223343332212'; '132343332212'; % /* 2055 */
'223334323121'; '223334332121'; '223343332212'; '132343332212'; '223334322221'; % /* 2060 */
'223334332121'; '223343332212'; '132343332212'; '223334322221'; '223334332121'; % /* 2065 */
'223343332212'; '132343332212'; '222433422221'; '223334332121'; '223343332212'; % /* 2070 */
'132343332212'; '222433422221'; '223334323121'; '223343332212'; '123343332212'; % /* 2075 */
'222433422221'; '223334323121'; '223334332212'; '123343332212'; '222433422221'; % /* 2080 */
'223334323121'; '223334332211'; '223343332212'; '132433332221'; '223334323112'; % /* 2085 */
'223334332211'; '223343332212'; '132343332221'; '223334323112'; '223334332121'; % /* 2090 */
'223343332212'; '132343332221'; '223334322212'; '223334332121'; '223343332212'; % /* 2095 */
'132343332221'; '223333422212'; '223334332121'; '223343332212'; % /* 2099 */
];
YearDays=zeros(200,14);
YearDays(:,1)=1900:2099;
for idx=1:12;YearDays(:,2+idx)=28+str2num(YearInfos_GanZhiDate(:,idx));end
YearDays(:,2)=sum(YearDays(:,3:end),2);
end
% -----------------------------------------------------------------
function YearDays=YearInfos2YearDays_LunarDate()
% YearDays=YearInfos2YearDays_LunarDate()
%
YearInfos = [
% /* encoding:
% b bbbbbbbbbbbb bbbb
% bit% 1 111111000000 0000
% 6 543210987654 3210
% . ............ ....
% month% 000000000111
% M 123456789012 L
%
% b_j = 1 for long month'; 'b_j = 0 for short month
% L is the leap month