src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 311
e676ed461b5b
parent 305
4db64fe30588
child 341
52831b82b3fd
equal deleted inserted replaced
310:523fe96baeca 311:e676ed461b5b
860 pool_free(pool, pg); 860 pool_free(pool, pg);
861 pool_free(pool, dir); 861 pool_free(pool, dir);
862 } 862 }
863 863
864 time_t pg_convert_timestamp(const char *timestamp) { 864 time_t pg_convert_timestamp(const char *timestamp) {
865 // TODO: this is a very basic implementation that needs some work 865 struct tm tm;
866 // format yyyy-mm-dd HH:MM:SS 866 if(pg_convert_timestamp_tm(timestamp, &tm)) {
867
868 size_t len = timestamp ? strlen(timestamp) : 0;
869 if(len < 19) {
870 return 0; 867 return 0;
871 } else if(len > 63) { 868 }
872 return 0;
873 }
874
875 char buf[64];
876 memcpy(buf, timestamp, len);
877
878 char *year_str = buf;
879 year_str[4] = '\0';
880
881 char *month_str = buf + 5;
882 month_str[2] = '\0';
883
884 char *day_str = buf + 8;
885 day_str[2] = '\0';
886
887 char *hour_str = buf + 11;
888 hour_str[2] = '\0';
889
890 char *minute_str = buf + 14;
891 minute_str[2] = '\0';
892
893 char *second_str = buf + 17;
894 second_str[2] = '\0';
895
896 struct tm tm;
897 memset(&tm, 0, sizeof(struct tm));
898 tm.tm_year = atoi(year_str) - 1900;
899 tm.tm_mon = atoi(month_str) - 1;
900 tm.tm_mday = atoi(day_str);
901 tm.tm_hour = atoi(hour_str);
902 tm.tm_min = atoi(minute_str);
903 tm.tm_sec = atoi(second_str);
904
905 #ifdef __FreeBSD__ 869 #ifdef __FreeBSD__
906 return timelocal(&tm); 870 return timelocal(&tm);
907 #else 871 #else
908 return mktime(&tparts) - timezone; 872 return mktime(&tparts) - timezone;
909 #endif 873 #endif
910 } 874 }
875
876 int pg_convert_timestamp_tm(const char *timestamp, struct tm *tm) {
877 // TODO: this is a very basic implementation that needs some work
878 // format yyyy-mm-dd HH:MM:SS
879
880 memset(tm, 0, sizeof(struct tm));
881 size_t len = timestamp ? strlen(timestamp) : 0;
882 if(len < 19) {
883 return 1;
884 } else if(len > 63) {
885 return 1;
886 }
887
888 char buf[64];
889 memcpy(buf, timestamp, len);
890
891 char *year_str = buf;
892 year_str[4] = '\0';
893
894 char *month_str = buf + 5;
895 month_str[2] = '\0';
896
897 char *day_str = buf + 8;
898 day_str[2] = '\0';
899
900 char *hour_str = buf + 11;
901 hour_str[2] = '\0';
902
903 char *minute_str = buf + 14;
904 minute_str[2] = '\0';
905
906 char *second_str = buf + 17;
907 second_str[2] = '\0';
908
909 tm->tm_year = atoi(year_str) - 1900;
910 tm->tm_mon = atoi(month_str) - 1;
911 tm->tm_mday = atoi(day_str);
912 tm->tm_hour = atoi(hour_str);
913 tm->tm_min = atoi(minute_str);
914 tm->tm_sec = atoi(second_str);
915
916 return 0;
917 }

mercurial