Changeset: c7abe021a0a4 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c7abe021a0a4
Modified Files:
        monetdb5/extras/rdf/rdf_shredder.c
        monetdb5/extras/rdf/rdftypes.c
        monetdb5/extras/rdf/rdftypes.h
Branch: rdf
Log Message:

Add function for encoding/decoding datetime value


diffs (134 lines):

diff --git a/monetdb5/extras/rdf/rdf_shredder.c 
b/monetdb5/extras/rdf/rdf_shredder.c
--- a/monetdb5/extras/rdf/rdf_shredder.c
+++ b/monetdb5/extras/rdf/rdf_shredder.c
@@ -211,8 +211,11 @@ getObjectType_and_Value(unsigned char* o
                        
                        subLen = (int) (pos - (str)objStr - 28);
                        valuepart = substring((char*)objStr, 2 , subLen); 
+                       
+                       if (convertDateTimeStringToTimeT(valuepart, 
subLen,&nTime) == 1){
 
-                       if (convertDateTimeStringToTimeT(valuepart, 
subLen,&nTime) == 1){
+                               //
+                               //
                                //store numeric datetime value in long value
                                realLng = nTime; 
                                VALset(vrPtrRealValue,TYPE_lng, &realLng);
@@ -442,18 +445,22 @@ tripleHandler(void* user_data, const rap
                                decodeValueFromOid(bun, objType, &vrRealValue);
                                printf("Decoded double value is: %.10f \n", 
vrRealValue.val.dval);
                        }
-
+                       
                        if (objType == DATETIME){
                                time_t t; 
-                               struct tm *timeinfo;
                                decodeValueFromOid(bun, objType, &vrRealValue);
                                printf("Decoded numeric datetime value is: %lld 
\n", vrRealValue.val.lval);
                                t = (time_t) vrRealValue.val.lval;
-                               timeinfo = localtime(&t);
-                               printf ( "Current local time and date: %s", 
asctime (timeinfo) );
+                               
+                               //Check using mtime
+                               {
+                               timestamp ts; 
+                               convertTMtimeToMTime(t, &ts);
+                               printf("Day times is %d (seconds) \n",ts.msecs);
+                               printf("Date is %d (days) \n", ts.days);
+                               }
                        }
                        */
-
                        //printf("Object string is %s --> object type is %d 
(oid = " BUNFMT " \n",objStr,objType, bun);
 
                        bun = BUN_NONE;
diff --git a/monetdb5/extras/rdf/rdftypes.c b/monetdb5/extras/rdf/rdftypes.c
--- a/monetdb5/extras/rdf/rdftypes.c
+++ b/monetdb5/extras/rdf/rdftypes.c
@@ -367,6 +367,21 @@ char rdfcast(ObjectType srcT, ObjectType
        }       
 }
 
+/*
+ * Convert struct tm to time_t, keeping the time_zone information
+ */
+
+static
+time_t tm2time(const struct tm *src)
+{
+       struct tm tmp;
+
+       tmp = *src;
+
+       return timegm(&tmp) - src->tm_gmtoff;
+}
+
+
 int convertDateTimeStringToTimeT(char *sDateTime, int len, time_t *t){
        
        /*
@@ -409,7 +424,7 @@ int convertDateTimeStringToTimeT(char *s
        
        for (; j < numAcceptFormat; j++){
                if ((strptime(sDateTime, acceptFormat[j], &tm1)) != NULL){      
        
-                       *t = mktime(&tm1);
+                       *t = tm2time(&tm1);
                        return 1; 
                }
        }
@@ -419,6 +434,11 @@ int convertDateTimeStringToTimeT(char *s
        return 0; 
 }
 
+//TODO: For Datetime, we may use function in mtime in order to directly 
convert datetime string
+//to mtime timestamp. Then, encode the timestamp in the oid, in which, 1 bit 
for sign of date, 27 bits for days value, 
+//32 bits for msecs. (We can also use 28bits for msecs, and 32 bits for date). 
+//However, we need to verify that mtime accepts rdf datetime format
+
 void 
 encodeValueInOid(ValPtr vrPtrRealValue, ObjectType objType, BUN* bun){
 
@@ -507,6 +527,23 @@ decodeValueFromOid(BUN bun, ObjectType o
        }
 }
 
+/*
+ * Convert value from tm format to timestamp of monet mtime
+ * */
+void convertTMtimeToMTime(time_t t, timestamp *ts){
+       struct tm *timeinfo;
+       char buf[128], *s1 = buf;
+       *s1 = 0;
+
+       timeinfo = gmtime(&t);
+       //printf ( "Current local time and date: %s", asctime (timeinfo) );
+
+       //Reformat the datetime string
+       sprintf(s1, "%d-%02d-%02dT%d:%d:%d", timeinfo->tm_year + 1900, 
timeinfo->tm_mon + 1, timeinfo->tm_mday,
+                       timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
+
+       MTIMEtimestamp_fromstr(ts, (const char* const*) &s1);
+}
 
 /*
 static
diff --git a/monetdb5/extras/rdf/rdftypes.h b/monetdb5/extras/rdf/rdftypes.h
--- a/monetdb5/extras/rdf/rdftypes.h
+++ b/monetdb5/extras/rdf/rdftypes.h
@@ -24,6 +24,8 @@
 #ifndef _RDFTYPES_H_
 #define _RDFTYPES_H_
 
+#include <mtime.h>
+
 #ifdef WIN32
 #ifndef LIBRDF
 #define rdf_export extern __declspec(dllimport)
@@ -78,4 +80,7 @@ decodeValueFromOid(BUN bun, ObjectType o
 rdf_export int 
 convertDateTimeStringToTimeT(char *sDateTime, int len, time_t *t);
 
+rdf_export void
+convertTMtimeToMTime(time_t t, timestamp *ts);
+
 #endif /* _RDFTYPES_H_ */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to