Update of /cvsroot/monetdb/MonetDB5/src/modules/atoms
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv11441
Modified Files:
mtime.mx
Log Message:
added str_to_date and date_to_str based on strptime and strftime
Index: mtime.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/atoms/mtime.mx,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- mtime.mx 30 Nov 2007 12:36:05 -0000 1.101
+++ mtime.mx 10 Dec 2007 21:29:13 -0000 1.102
@@ -708,6 +708,14 @@
comment "parse the old duration format and
return an (estimated) number of days.";
+command str_to_date(s:str, format:str) :date
+address MTIMEstrptime
+comment "create a date from the string, using the specified format (see man
strptime)";
+
+command date_to_str(d:date, format:str) :str
+address MTIMEstrftime
+comment "create a string from the date, using the specified format (see man
strftime)";
+
@+ Utilities
The Monet V4 procs are converted into functions.
@mal
@@ -1041,6 +1049,10 @@
mtime_export int rule_fromstr(str buf, int *len, rule **d);
mtime_export int rule_tostr(str *buf, int *len, rule *r);
mtime_export int tzone_fromstr(str buf, int *len, tzone **d);
+
+mtime_export str MTIMEstrptime(date *d, str *s, str *format);
+mtime_export str MTIMEstrftime(str *s, date *d, str *format);
+
@= ExtractExport
mtime_export str [EMAIL PROTECTED]@2_bulk(int *ret, int *bid);
@h
@@ -3900,3 +3912,39 @@
@:Extract(daytime,seconds,int)@
@:Extract(daytime,milliseconds,int)@
@}
+
+str
+MTIMEstrptime(date *d, str *s, str *format)
+{
+#ifdef HAVE_STRPTIME
+ struct tm t;
+
+ memset(&t, 0, sizeof(struct tm));
+ if (strptime(*s, *format, &t) == NULL)
+ throw(MAL, "mtime.str_to_date", "format '%s', doesn't match
date '%s'\n", *format, *s);
+ *d = todate(t.tm_mday, t.tm_mon+1, t.tm_year+1900);
+ return MAL_SUCCEED;
+#endif
+ throw(MAL, "mtime.str_to_date", "strptime support missing");
+}
+
+str MTIMEstrftime(str *s, date *d, str *format)
+{
+#ifdef HAVE_STRFTIME
+ struct tm t;
+ char buf[BUFSIZ+1];
+ size_t sz;
+ int mon, year;
+
+ memset(&t, 0, sizeof(struct tm));
+ fromdate( (int)*d, &t.tm_mday, &mon, &year);
+ t.tm_mon = mon-1;
+ t.tm_year = year-1900;
+ if ((sz = strftime(buf, BUFSIZ, *format, &t)) == 0)
+ throw(MAL, "mtime.date_to_str", "failed to convert date to
string using format '%s'\n", *format);
+ *s = GDKmalloc(sz+1);
+ strncpy(*s, buf, sz+1);
+ return MAL_SUCCEED;
+#endif
+ throw(MAL, "mtime.str_to_date", "strptime support missing");
+}
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins