Changeset: afe87d6e8196 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=afe87d6e8196 Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/MAL-signatures_nocfitsio.stable.out clients/Tests/MAL-signatures_nogeom.stable.out monetdb5/modules/atoms/mtime.c Branch: default Log Message:
Merge with Feb2013 branch. diffs (truncated from 1154 to 300 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -38785,7 +38785,7 @@ comment Return hex string representation command clients.shutdown(forced:bit):void address CLTshutdown; -comment Close all client connections. If forced=false theclients are moved into FINISHING mode, which means thatthe process stops at the next cycle of the scenario.If forced=true all client processes are immediately killed +comment Close all client connections. If forced=false theclients are moved into finishing mode, which means thatthe process stops at the next cycle of the scenario.If forced=true all client processes are immediately killed pattern clients.setTimeout(q:lng,s:lng):void address CLTsetTimeout; diff --git a/clients/Tests/MAL-signatures_nocfitsio.stable.out b/clients/Tests/MAL-signatures_nocfitsio.stable.out --- a/clients/Tests/MAL-signatures_nocfitsio.stable.out +++ b/clients/Tests/MAL-signatures_nocfitsio.stable.out @@ -38785,7 +38785,7 @@ comment Return hex string representation command clients.shutdown(forced:bit):void address CLTshutdown; -comment Close all client connections. If forced=false theclients are moved into FINISHING mode, which means thatthe process stops at the next cycle of the scenario.If forced=true all client processes are immediately killed +comment Close all client connections. If forced=false theclients are moved into finishing mode, which means thatthe process stops at the next cycle of the scenario.If forced=true all client processes are immediately killed pattern clients.setTimeout(q:lng,s:lng):void address CLTsetTimeout; diff --git a/clients/Tests/MAL-signatures_nogeom.stable.out b/clients/Tests/MAL-signatures_nogeom.stable.out --- a/clients/Tests/MAL-signatures_nogeom.stable.out +++ b/clients/Tests/MAL-signatures_nogeom.stable.out @@ -38757,7 +38757,7 @@ comment Return hex string representation command clients.shutdown(forced:bit):void address CLTshutdown; -comment Close all client connections. If forced=false theclients are moved into FINISHING mode, which means thatthe process stops at the next cycle of the scenario.If forced=true all client processes are immediately killed +comment Close all client connections. If forced=false theclients are moved into finishing mode, which means thatthe process stops at the next cycle of the scenario.If forced=true all client processes are immediately killed pattern clients.setTimeout(q:lng,s:lng):void address CLTsetTimeout; diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c --- a/monetdb5/modules/atoms/mtime.c +++ b/monetdb5/modules/atoms/mtime.c @@ -22,7 +22,7 @@ * @a Peter Boncz, Martin van Dinther * @v 1.0 * - * @+ Temporal Module + * Temporal Module * The goal of this module is to provide adequate functionality for * storing and manipulated time-related data. The minimum requirement * is that data can easily be imported from all common commercial @@ -71,7 +71,7 @@ * default value of the local timezone is plain GMT). * @end table * - * @+ Limitations + * Limitations * The valid ranges of the various data types are as follows: * * @table @samp @@ -196,7 +196,7 @@ * dynamic in this structure. The timezone_setlocal would just set the * string name of the timezone. * - * @+ Time/date comparison + * Time/date comparison */ #include "monetdb_config.h" @@ -224,9 +224,6 @@ tzone tzone_local; -/* - * @+ Defines - */ static const char *MONTHS[13] = { NULL, "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" @@ -242,25 +239,28 @@ static const char *COUNT1[7] = { static const char *COUNT2[7] = { NULL, "1st", "2nd", "3rd", "4th", "5th", "last" }; -static int NODAYS[13] = { +static int LEAPDAYS[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static int CUMDAYS[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; +static int CUMLEAPDAYS[13] = { + 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 +}; static date DATE_MAX, DATE_MIN; /* often used dates; computed once */ #define YEAR_MAX 5867411 #define YEAR_MIN (-YEAR_MAX) -#define MONTHDAYS(m,y) ((m) != 2 ? NODAYS[m] : leapyear(y) ? 29 : 28) +#define MONTHDAYS(m,y) ((m) != 2 ? LEAPDAYS[m] : leapyear(y) ? 29 : 28) #define YEARDAYS(y) (leapyear(y) ? 366 : 365) -#define DATE(d,m,y) ((m) > 0 && (m) <= 12 && (d) > 0&& (y) != 0 && (y) >= YEAR_MIN && (y) <= YEAR_MAX && (d) <= MONTHDAYS(m, y)) +#define DATE(d,m,y) ((m) > 0 && (m) <= 12 && (d) > 0 && (y) != 0 && (y) >= YEAR_MIN && (y) <= YEAR_MAX && (d) <= MONTHDAYS(m, y)) #define TIME(h,m,s,x) ((h) >= 0 && (h) < 24 && (m) >= 0 && (m) < 60 && (s) >= 0 && (s) < 60 && (x) >= 0 && (x) < 1000) #define LOWER(c) ((c) >= 'A' && (c) <= 'Z' ? (c) + 'a' - 'A' : (c)) /* - * @+ auxiliary functions + * auxiliary functions */ static union { @@ -274,8 +274,6 @@ static union { timestamp *timestamp_nil = NULL; static tzone *tzone_nil = NULL; -static void date_prelude(void); - int TYPE_date; int TYPE_daytime; int TYPE_timestamp; @@ -322,9 +320,19 @@ todate(int day, int month, int year) static void fromdate(int n, int *d, int *m, int *y) { - int month, year = n / 365; - int day = (n - year * 365) - leapyears(year >= 0 ? year - 1 : year); - + int day, month, year; + + if (n == int_nil) { + if (d) + *d = int_nil; + if (m) + *m = int_nil; + if (y) + *y = int_nil; + return; + } + year = n / 365; + day = (n - year * 365) - leapyears(year >= 0 ? year - 1 : year); if (n < 0) { year--; while (day >= 0) { @@ -338,21 +346,40 @@ fromdate(int n, int *d, int *m, int *y) day += YEARDAYS(year); } } + if (d == 0 && m == 0) { + if (y) + *y = (year <= 0) ? year - 1 : year; /* HACK: hide year 0 */ + return; + } + day++; - for (month = 1; month <= 12; month++) { - int days = MONTHDAYS(month, year); - - if (day <= days) - break; - day -= days; + if (leapyear(year)) { + for (month = day / 31 == 0 ? 1 : day / 31; month <= 12; month++) + if (day > CUMLEAPDAYS[month - 1] && day <= CUMLEAPDAYS[month]) { + if (m) + *m = month; + if (d == 0) + return; + break; + } + day -= CUMLEAPDAYS[month - 1]; + } else { + for (month = day / 31 == 0 ? 1 : day / 31; month <= 12; month++) + if (day > CUMDAYS[month - 1] && day <= CUMDAYS[month]) { + if (m) + *m = month; + if (d == 0) + return; + break; + } + day -= CUMDAYS[month - 1]; } - if (n != int_nil) { + if (d) *d = day; + if (m) *m = month; + if (y) *y = (year <= 0) ? year - 1 : year; /* HACK: hide year 0 */ - } else { - *d = *m = *y = int_nil; - } } static daytime @@ -475,7 +502,7 @@ compute_rule(const rule *val, int y) return d; } -#define BEFORE(d1, m1, d2, m2) ((d1) < (d2) || ((d1) == (d2) && (m1) <= (m2))) +#define BEFORE(d1, m1, d2, m2) ((d1) < (d2) || ((d1) == (d2) && (m1) <= (m2))) static int timestamp_inside(timestamp *ret, const timestamp *t, const tzone *z, lng offset) @@ -484,7 +511,6 @@ timestamp_inside(timestamp *ret, const t lng add = (offset != (lng) 0) ? offset : (get_offset(z)) * (lng) 60000; int start_days, start_msecs, end_days, end_msecs, year; rule start, end; - int dummy; MTIMEtimestamp_add(ret, t, &add); @@ -497,7 +523,7 @@ timestamp_inside(timestamp *ret, const t start_msecs = start.s.minutes * 60000; end_msecs = end.s.minutes * 60000; - fromdate((int) ret->days, &dummy, &dummy, &year); + fromdate((int) ret->days, NULL, NULL, &year); start_days = compute_rule(&start, year); end_days = compute_rule(&end, year); @@ -509,7 +535,7 @@ timestamp_inside(timestamp *ret, const t } /* - * @+ ADT implementations + * ADT implementations * @- date */ int @@ -964,7 +990,7 @@ rule_fromstr(const char *buf, int *len, } /* assign if semantically ok */ - if (day >= 1 && day <= NODAYS[month] && + if (day >= 1 && day <= LEAPDAYS[month] && hours >= 0 && hours < 60 && minutes >= 0 && minutes < 60) { (*d)->s.month = month; @@ -1091,20 +1117,8 @@ tzone_tostr(str *buf, int *len, const tz } /* - * @+ operator implementations + * operator implementations */ -static void -date_prelude(void) -{ - MONTHS[0] = (str) str_nil; - DAYS[0] = (str) str_nil; - NODAYS[0] = int_nil; - DATE_MAX = todate(31, 12, YEAR_MAX); - DATE_MIN = todate(1, 1, YEAR_MIN); - tzone_local.dst = 0; - set_offset(&tzone_local, 0); -} - static str tzone_set_local(const tzone *z) { @@ -1243,7 +1257,14 @@ MTIMEprelude(void) TYPE_timestamp = ATOMindex("timestamp"); TYPE_tzone = ATOMindex("timezone"); TYPE_rule = ATOMindex("rule"); - date_prelude(); + + MONTHS[0] = (str) str_nil; + DAYS[0] = (str) str_nil; + LEAPDAYS[0] = int_nil; + DATE_MAX = todate(31, 12, YEAR_MAX); + DATE_MIN = todate(1, 1, YEAR_MIN); + tzone_local.dst = 0; + set_offset(&tzone_local, 0); tz = *tzone_nil; /* to ensure initialized variables */ @@ -1613,8 +1634,7 @@ MTIMEdate_extract_year(int *ret, const d if (*v == date_nil) { *ret = int_nil; } else { - int dummy; - fromdate((int) *v, &dummy, &dummy, ret); + fromdate((int) *v, NULL, NULL, ret); } return MAL_SUCCEED; } @@ -1626,8 +1646,7 @@ MTIMEdate_extract_month(int *ret, const if (*v == date_nil) { *ret = int_nil; } else { - int dummy; - fromdate((int) *v, &dummy, ret, &dummy); + fromdate((int) *v, NULL, ret, NULL); } return MAL_SUCCEED; } @@ -1639,8 +1658,7 @@ MTIMEdate_extract_day(int *ret, const da if (*v == date_nil) { *ret = int_nil; } else { - int dummy; - fromdate((int) *v, ret, &dummy, &dummy); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list