UtDate.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef UTDATE_H
00008 #define UTDATE_H
00009
00010 #include <cstdlib>
00011 #include <time.h>
00012
00013 #include "Constants.h"
00014 #include "DataMethod.hxx"
00015 #include "StringOps.h"
00016 #include "Logger.h"
00017
00019 template<typename DataType>
00020 class UtDate : public DataMethod<DataType>
00021 {
00022 public:
00024 UtDate() { DataMethod<DataType>::methodName = "UtDate"; }
00025
00027 virtual ~UtDate() { }
00028
00030 void setSource(IntMap& tbls, IntMap& cols, StringMap units)
00031 {
00032 dateObsColNo = cols[0];
00033 if (dateObsColNo < 0)
00034 {
00035 throw DataMethodException("JulianDayNum method. Couldn't source");
00036 }
00037 }
00038
00040 void setTarget(IntMap& cols, StringMap units)
00041 {
00042 utDateColNo = cols[0];
00043 }
00044
00046 void doit(TableData<DataType>& data, int row1, int row2)
00047 {
00048 for (int rowNo = row1; rowNo < row2; ++rowNo)
00049 {
00050 time_t difftime;
00051 tm ctm;
00052 tm *dtm;
00053 char chiltime[20] = "";
00054 std::string date;
00055 std::string timeStr;
00056 size_t found;
00057 data.value(dateObsColNo, rowNo, date);
00058 found = date.rfind('.');
00059 date = date.substr(0, found);
00060 strptime(date.c_str(), "%Y-%m-%dT%H:%M:%S", &ctm);
00061 ctm.tm_isdst = 0;
00062
00063 if (ctm.tm_hour <= 16)
00064 {
00065 difftime = mktime(&ctm)-86400;
00066 dtm = gmtime(&difftime);
00067 } else {
00068 dtm = &ctm;
00069 }
00070 strftime(chiltime, 20, "%Y%m%d", dtm);
00071 mUtDate = atoi(chiltime);
00072 data.assign(utDateColNo, rowNo, mUtDate);
00073 }
00074 }
00075
00076
00077 void doit2(TableData<DataType>& rawData, TableData<DataType>& data, int row1, int row2) { }
00078
00079 private:
00080 int dateObsColNo;
00081 int utDateColNo;
00082 int mUtDate;
00083 };
00084
00085 #endif
00086
00087
00088
00089