Changeset: 8f62c57b4ae8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8f62c57b4ae8
Modified Files:
sql/backends/monet5/sql_bat2time.c
Branch: datetrunc
Log Message:
Add trunaction to week
diffs (34 lines):
diff --git a/sql/backends/monet5/sql_bat2time.c
b/sql/backends/monet5/sql_bat2time.c
--- a/sql/backends/monet5/sql_bat2time.c
+++ b/sql/backends/monet5/sql_bat2time.c
@@ -386,7 +386,7 @@ date_trunc(timestamp *dt, const str *sca
{
str msg = MAL_SUCCEED;
timestamp ts;
- int y, m, d, one = 1;
+ int dow, y, m, d, one = 1;
if (truncate_check(scale) == 0)
throw(SQL, "sql.truncate", SQLSTATE(HY001) "Improper directive
");
@@ -404,7 +404,20 @@ date_trunc(timestamp *dt, const str *sca
ts.msecs = 0;
*dt = ts;
} }
- // week
+
+ if ( strcmp(*scale, "week") == 0){
+ if (timestamp_isnil(*bt)) {
+ *dt = *timestamp_nil;
+ } else {
+ ts = *bt;
+ ts.msecs = 0;
+ MTIMEdate_extract_ymd(&y, &m, &d, &ts.days);
+ MTIMEdate_extract_dayofweek(&dow, &ts.days);
+ d = d - dow + 1;
+ MTIMEdate_create(&ts.days, &y, &m, &d);
+ *dt = ts;
+ } }
+
if ( strcmp(*scale, "month") == 0){
if (timestamp_isnil(*bt)) {
*dt = *timestamp_nil;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list