text: /*
   * @Author: likai
   * @Date: 2022-01-05 18:16:57
   * @Last Modified by: likai
   * @Last Modified time: 2022-01-06 15:22:32
   * @Description: "test for timestamp"
   */
  
  #include "timestamp.h"
  #include "gtest/gtest.h"
  
  using namespace common;
  
  TEST(TimeStampTest, INVALID) {
      TimeStamp t1;
      EXPECT_EQ(t1.Valid(), false);
  }
  
  TEST(TimeStampTest, NOW) {
      TimeStamp now = TimeStamp::Now();
      EXPECT_EQ(now.Time(), time(NULL));
      struct timeval tv;
      gettimeofday(&tv, NULL);
      struct timeval tv2;
      now.GetTimeOfDay(&tv2);
      EXPECT_EQ(tv2.tv_sec, tv.tv_sec);
      // us maybe has errors
  }
  
  TEST(TimeStampTest, TZ) {
      TimeStamp now = TimeStamp::Now();
      std::string s1 = now.ToIso8601String(false).substr(0, 13);
      std::string s2 = now.ToIso8601String(true).substr(0, 13);
      if (now.CurrentTimezone() == 0) {
          EXPECT_EQ(s1, s2);
      } else {
          EXPECT_NE(s1, s2);
      }
  }