22 #include <drizzled/function/time/timestamp_diff.h>
23 #include <drizzled/time_functions.h>
37 if (args[0]->
get_date(ltime1, TIME_NO_ZERO_DATE) ||
38 args[1]->
get_date(ltime2, TIME_NO_ZERO_DATE))
41 if (calc_time_diff(<ime2,<ime1, 1,
42 &seconds, µseconds))
45 if (int_type == INTERVAL_YEAR ||
46 int_type == INTERVAL_QUARTER ||
47 int_type == INTERVAL_MONTH)
49 uint32_t year_beg, year_end, month_beg, month_end, day_beg, day_end;
51 uint32_t second_beg, second_end, microsecond_beg, microsecond_end;
55 year_beg= ltime2.year;
56 year_end= ltime1.year;
57 month_beg= ltime2.month;
58 month_end= ltime1.month;
61 second_beg= ltime2.hour * 3600 + ltime2.minute * 60 + ltime2.second;
62 second_end= ltime1.hour * 3600 + ltime1.minute * 60 + ltime1.second;
63 microsecond_beg= ltime2.second_part;
64 microsecond_end= ltime1.second_part;
68 year_beg= ltime1.year;
69 year_end= ltime2.year;
70 month_beg= ltime1.month;
71 month_end= ltime2.month;
74 second_beg= ltime1.hour * 3600 + ltime1.minute * 60 + ltime1.second;
75 second_end= ltime2.hour * 3600 + ltime2.minute * 60 + ltime2.second;
76 microsecond_beg= ltime1.second_part;
77 microsecond_end= ltime2.second_part;
81 years= year_end - year_beg;
82 if (month_end < month_beg || (month_end == month_beg && day_end < day_beg))
87 if (month_end < month_beg || (month_end == month_beg && day_end < day_beg))
88 months+= 12 - (month_beg - month_end);
90 months+= (month_end - month_beg);
92 if (day_end < day_beg)
94 else if ((day_end == day_beg) &&
95 ((second_end < second_beg) ||
96 (second_end == second_beg && microsecond_end < microsecond_beg)))
102 return months/12*neg;
103 case INTERVAL_QUARTER:
108 return seconds/86400L/7L*neg;
110 return seconds/86400L*neg;
112 return seconds/3600L*neg;
113 case INTERVAL_MINUTE:
114 return seconds/60L*neg;
115 case INTERVAL_SECOND:
117 case INTERVAL_MICROSECOND:
122 return (seconds*1000000L+microseconds)*neg;
135 str->append(func_name(), strlen(func_name()));
140 str->append(STRING_WITH_LEN(
"YEAR"));
142 case INTERVAL_QUARTER:
143 str->append(STRING_WITH_LEN(
"QUARTER"));
146 str->append(STRING_WITH_LEN(
"MONTH"));
149 str->append(STRING_WITH_LEN(
"WEEK"));
152 str->append(STRING_WITH_LEN(
"DAY"));
155 str->append(STRING_WITH_LEN(
"HOUR"));
157 case INTERVAL_MINUTE:
158 str->append(STRING_WITH_LEN(
"MINUTE"));
160 case INTERVAL_SECOND:
161 str->append(STRING_WITH_LEN(
"SECOND"));
163 case INTERVAL_MICROSECOND:
164 str->append(STRING_WITH_LEN(
"SECOND_FRAC"));
170 for (uint32_t i=0 ; i < 2 ; i++)
virtual void print(String *str)
TODO: Rename this file - func.h is stupid.
virtual bool get_date(type::Time <ime, uint32_t fuzzydate)
virtual void print(String *str)