implement date_from_string (close
@@ -74,9 +74,35 @@ HL_PRIM int hl_date_from_time( double time ) {
}
HL_PRIM int hl_date_from_string( vbyte *b, int len ) {
- uchar *str = (uchar*)b;
- hl_fatal("TODO");
- return *str;
+ struct tm t;
+ int o = 0;
+ const char *str = hl_to_utf8((uchar*)b);
+ bool recal = true;
+ memset(&t,0,sizeof(struct tm));
+ switch( strlen(str) ) {
+ case 19:
+ sscanf(str,"%4d-%2d-%2d %2d:%2d:%2d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
+ t.tm_isdst = -1;
+ break;
+ case 8:
+ sscanf(str,"%2d:%2d:%2d",&t.tm_hour,&t.tm_min,&t.tm_sec);
+ o = t.tm_sec + t.tm_min * 60 + t.tm_hour * 60 * 60;
+ recal = false;
+ break;
+ case 10:
+ sscanf(str,"%4d-%2d-%2d",&t.tm_year,&t.tm_mon,&t.tm_mday);
+ t.tm_isdst = -1;
+ break;
+ default:
+ hl_error("Invalid date format");
+ break;
+ }
+ if( recal ) {
+ t.tm_year -= 1900;
+ t.tm_mon--;
+ o = (int)mktime(&t);
+ }
+ return o;
}
HL_PRIM int hl_date_new( int y, int mo, int d, int h, int m, int s ) {
