* know bugs fixed !
[lichviet] / qml / LichViet / main.js
1 .pragma library
2
3 Qt.include("amlich-hnd.js");
4 Qt.include("amlich-aa98.js");
5 Qt.include("Settings.js");
6 Qt.include("Themes.js");
7 Qt.include("CacNgayLeTrongNam.js");
8 Qt.include("xemngaytotxau.js");
9
10 var localdate = new Date();
11
12 var curDay=localdate.getDate();
13 var curMonth=localdate.getMonth()+1;
14 var curYear=localdate.getFullYear();
15
16 var initcurDay;
17 var initcurMonth;
18 var initcurYear;
19
20 var lunarDay = getLunarDate(curDay,curMonth,curYear).day;
21 var lunarMonth = getLunarDate(curDay,curMonth,curYear).month;
22 var lunarYear = getCanChi(getLunarDate(curDay,curMonth,curYear))[2];
23 var lunarYearInt = getLunarDate(curDay,curMonth,curYear).year;
24 var jd = getLunarDate(curDay,curMonth,curYear).jd;
25 var lunarGioHoangDao = getGioHoangDao(jd);
26
27 var lunarDayCanChi = getCanChi(getLunarDate(curDay,curMonth,curYear))[0];
28 var lunarMonthCanChi = getCanChi(getLunarDate(curDay,curMonth,curYear))[1];
29
30 var day_info = get(curDay,curMonth, curYear, lunarDay, lunarMonth);
31 var isholiday = is_holiday(curDay,curMonth, curYear, lunarDay, lunarMonth);
32
33 var datetimedlg;
34 var amdatetimedlg;
35 var fullmonth;
36
37 function init(){
38     initcurDay = curDay;
39     initcurMonth = curMonth;
40     initcurYear = curYear;
41 }
42
43 function day_reset(){
44     curDay = initcurDay;
45 }
46
47 function calDays(){
48     console.log(curMonth)
49     if (curMonth == 4 || curMonth == 6 || curMonth == 9 || curMonth == 11)
50         return 30;
51     else
52         if (curMonth == 2){
53             var isLeapYear = (curYear % 4 === 0 && curYear % 100 !== 0) || (curYear % 400 ===0);
54             if (isLeapYear)
55                 return 29;
56             else
57                 return 28;
58         }
59     return 31;
60 }
61
62 function calDaysX(month, year){
63     if (month == 4 || month == 6 || month == 9 || month == 11)
64         return 30;
65     else
66         if (month == 2){
67             var isLeapYear = (year % 4 === 0 && year % 100 !== 0) || (year % 400 ===0);
68             if (isLeapYear)
69                 return 29;
70             else
71                 return 28;
72         }
73     else
74     return 31;
75 }
76
77 function thu(){
78     return getTHU(jd);
79 }
80
81 function lunarTietKhi(){
82     return TIETKHI[getSunLongitude(jd+1,7.0)];
83 }
84
85 function reset_to_default_day(txtTHU, txtInfo, txtDAYAmLich){
86     localdate = new Date();
87
88     curDay=localdate.getDate();
89     curMonth=localdate.getMonth()+1;
90     curYear=localdate.getFullYear();
91
92     changeDay(curDay, txtTHU, txtInfo, txtDAYAmLich);
93 }
94
95 function changeDay(newday, txtTHU, txtInfo, txtDAYAmLich){
96     curDay = newday;
97     recalculate();
98
99     txtTHU.text=__txtTHU_format();
100     txtInfo.text=__txtInfo_format();
101     txtDAYAmLich.text=__txtDAYAmLich_format();
102 }
103
104 function createDateTimeDialog(parent){
105     datetimedlg = createObject("DateTimeDialog.qml", parent);
106     amdatetimedlg = createObject("AmDateTimeDialog.qml", parent);
107     fullmonth = createObject("FullMonth.qml", parent);
108 }
109
110 function __txtTHU_format(){
111     return getTHU(jd);
112 }
113
114 function __txtInfo_format(){
115     return day_info;
116 }
117
118 function __txtDAYAmLich_format(){
119     return "Ngày <b>"+lunarDay+" ("+lunarDayCanChi+")</b><br>Tháng <b>"+lunarMonth+" ("+lunarMonthCanChi+")</b><br>Năm <b>"+lunarYearInt+" ("+lunarYear+")</b>";
120 }
121
122 function recalculate(){
123     lunarDay = getLunarDate(curDay,curMonth,curYear).day;
124     lunarMonth = getLunarDate(curDay,curMonth,curYear).month;
125     lunarYear = getCanChi(getLunarDate(curDay,curMonth,curYear))[2];
126     lunarYearInt = getLunarDate(curDay,curMonth,curYear).year;
127     jd = getLunarDate(curDay,curMonth,curYear).jd;
128     lunarGioHoangDao = getGioHoangDao(jd);
129
130     lunarDayCanChi = getCanChi(getLunarDate(curDay,curMonth,curYear))[0];
131     lunarMonthCanChi = getCanChi(getLunarDate(curDay,curMonth,curYear))[1];
132
133     day_info = get(curDay,curMonth, lunarDay, lunarMonth);
134     isholiday = is_holiday(curDay,curMonth, curYear, lunarDay, lunarMonth);
135 }
136
137 function createObject(sourceFile, parentObject) {
138     var component = Qt.createComponent(sourceFile);
139     var guiObject = component.createObject(parentObject);
140
141     if (guiObject === null) {
142         console.log("Error creating object");
143     }
144     else {
145         return guiObject
146     }
147 }