kspread
kspread_functions_helper.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qdatetime.h>
00022
00023 #include "kspread_functions_helper.h"
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 int KSpread::daysPerYear(QDate const & date, int basis)
00067 {
00068 switch( basis )
00069 {
00070 case 0:
00071 return 360;
00072
00073 case 1:
00074 if ( QDate::leapYear( date.year() ) )
00075 return 366;
00076 return 365;
00077
00078 case 2:
00079 return 360;
00080 case 3:
00081 return 365;
00082 case 4:
00083 return 360;
00084 }
00085
00086 return -1;
00087 }
00088
00089 int KSpread::daysBetweenDates(QDate const & date1, QDate const & date2, int basis)
00090 {
00091 int day1, day2, month1, month2, year1, year2;
00092 bool isLeapYear = false;
00093 int days, months, years;
00094
00095 day1 = date1.day();
00096 month1 = date1.month();
00097 year1 = date1.year();
00098 day2 = date2.day();
00099 month2 = date2.month();
00100 year2 = date2.year();
00101
00102 years = year2 - year1;
00103 months = month2 - month1 + years * 12;
00104 days = day2 - day1;
00105
00106 isLeapYear = QDate::leapYear( year1 );
00107
00108 switch (basis)
00109 {
00110 case 0:
00111 if ( month1 == 2 && month2 != 2 && year1 == year2 )
00112 {
00113 if ( isLeapYear )
00114 return months * 30 + days - 1;
00115 else
00116 return months * 30 + days - 2;
00117 }
00118 return months * 30 + days;
00119
00120 case 1:
00121
00122
00123 case 2:
00124
00125
00126 case 3:
00127 return date1.daysTo( date2 );
00128
00129 case 4:
00130 return months * 30 + days;
00131 }
00132
00133 return -1;
00134 }
00135
|