[TD-2700]<fix>: fix incorrect generated time window.
This commit is contained in:
parent
c718cf4834
commit
7490333616
|
@ -10,3 +10,5 @@ ELSEIF (TD_WINDOWS)
|
|||
ENDIF ()
|
||||
|
||||
ADD_SUBDIRECTORY(src/detail)
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
|
||||
|
|
|
@ -486,7 +486,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
|
|||
start = (delta / pInterval->sliding + factor) * pInterval->sliding;
|
||||
|
||||
if (pInterval->intervalUnit == 'd' || pInterval->intervalUnit == 'w') {
|
||||
/*
|
||||
/*
|
||||
* here we revised the start time of day according to the local time zone,
|
||||
* but in case of DST, the start time of one day need to be dynamically decided.
|
||||
*/
|
||||
|
@ -502,8 +502,9 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
|
|||
}
|
||||
|
||||
int64_t end = start + pInterval->interval - 1;
|
||||
if (end < t) {
|
||||
while(end < t) { // move forward to the correct time window
|
||||
start += pInterval->sliding;
|
||||
end = start + pInterval->interval - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
FIND_PATH(HEADER_GTEST_INCLUDE_DIR gtest.h /usr/include/gtest /usr/local/include/gtest)
|
||||
FIND_LIBRARY(LIB_GTEST_STATIC_DIR libgtest.a /usr/lib/ /usr/local/lib)
|
||||
|
||||
IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR)
|
||||
MESSAGE(STATUS "gTest library found, build unit test")
|
||||
|
||||
INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR})
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
||||
|
||||
ADD_EXECUTABLE(osTest ${SOURCE_LIST})
|
||||
TARGET_LINK_LIBRARIES(osTest taos osdetail tutil common gtest pthread)
|
||||
ENDIF()
|
|
@ -0,0 +1,34 @@
|
|||
#include "os.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "taos.h"
|
||||
#include "tstoken.h"
|
||||
#include "tutil.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
// test function in os module
|
||||
TEST(testCase, parse_time) {
|
||||
taos_options(TSDB_OPTION_TIMEZONE, "GMT-8");
|
||||
deltaToUtcInitOnce();
|
||||
|
||||
// window: 1500000001000, 1500002000000
|
||||
// pQuery->interval: interval: 86400000, sliding:3600000
|
||||
int64_t key = 1500000001000;
|
||||
SInterval interval = {0};
|
||||
interval.interval = 86400000;
|
||||
interval.intervalUnit = 'd';
|
||||
interval.sliding = 3600000;
|
||||
interval.slidingUnit = 'h';
|
||||
|
||||
int64_t s = taosTimeTruncate(key, &interval, TSDB_TIME_PRECISION_MILLI);
|
||||
ASSERT_TRUE(s + interval.interval >= key);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue