| 332 | } |
| 333 | |
| 334 | TEST(TimestampTest, Basic) { |
| 335 | // Fix current time to determine the behavior parsing 2-digit year format |
| 336 | // Set it to 03/01 to test 02/29 edge cases. |
| 337 | TimestampValue now(date(1980, 3, 1), time_duration(16, 14, 24)); |
| 338 | |
| 339 | char s1[] = "2012-01-20 01:10:01"; |
| 340 | char s2[] = "1990-10-20 10:10:10.123456789 "; |
| 341 | char s3[] = " 1990-10-20 10:10:10.123456789"; |
| 342 | |
| 343 | TimestampValue v1 = TimestampValue::ParseSimpleDateFormat(s1, strlen(s1)); |
| 344 | TimestampValue v2 = TimestampValue::ParseSimpleDateFormat(s2, strlen(s2)); |
| 345 | TimestampValue v3 = TimestampValue::ParseSimpleDateFormat(s3, strlen(s3)); |
| 346 | |
| 347 | EXPECT_EQ(v1.date().year(), 2012); |
| 348 | EXPECT_EQ(v1.date().month(), 1); |
| 349 | EXPECT_EQ(v1.date().day(), 20); |
| 350 | EXPECT_EQ(v1.time().hours(), 1); |
| 351 | EXPECT_EQ(v1.time().minutes(), 10); |
| 352 | EXPECT_EQ(v1.time().seconds(), 1); |
| 353 | EXPECT_EQ(v1.time().fractional_seconds(), 0); |
| 354 | EXPECT_EQ(v2.time().fractional_seconds(), 123456789); |
| 355 | |
| 356 | EXPECT_NE(v1, v2); |
| 357 | EXPECT_EQ(v2, v3); |
| 358 | EXPECT_LT(v2, v1); |
| 359 | EXPECT_LE(v2, v1); |
| 360 | EXPECT_GT(v1, v2); |
| 361 | EXPECT_GE(v2, v3); |
| 362 | |
| 363 | EXPECT_NE(RawValue::GetHashValue(&v1, ColumnType(TYPE_TIMESTAMP), 0), |
| 364 | RawValue::GetHashValue(&v2, ColumnType(TYPE_TIMESTAMP), 0)); |
| 365 | EXPECT_EQ(RawValue::GetHashValue(&v3, ColumnType(TYPE_TIMESTAMP), 0), |
| 366 | RawValue::GetHashValue(&v2, ColumnType(TYPE_TIMESTAMP), 0)); |
| 367 | |
| 368 | char s4[] = "2012-01-20T01:10:01"; |
| 369 | char s5[] = "1990-10-20T10:10:10.123456789"; |
| 370 | |
| 371 | TimestampValue v4 = TimestampValue::ParseSimpleDateFormat(s4, strlen(s4)); |
| 372 | TimestampValue v5 = TimestampValue::ParseSimpleDateFormat(s5, strlen(s5)); |
| 373 | |
| 374 | EXPECT_EQ(v4.date().year(), 2012); |
| 375 | EXPECT_EQ(v4.date().month(), 1); |
| 376 | EXPECT_EQ(v4.date().day(), 20); |
| 377 | EXPECT_EQ(v4.time().hours(), 1); |
| 378 | EXPECT_EQ(v4.time().minutes(), 10); |
| 379 | EXPECT_EQ(v4.time().seconds(), 1); |
| 380 | EXPECT_EQ(v4.time().fractional_seconds(), 0); |
| 381 | EXPECT_EQ(v5.date().year(), 1990); |
| 382 | EXPECT_EQ(v5.date().month(), 10); |
| 383 | EXPECT_EQ(v5.date().day(), 20); |
| 384 | EXPECT_EQ(v5.time().hours(), 10); |
| 385 | EXPECT_EQ(v5.time().minutes(), 10); |
| 386 | EXPECT_EQ(v5.time().seconds(), 10); |
| 387 | EXPECT_EQ(v5.time().fractional_seconds(), 123456789); |
| 388 | |
| 389 | // Test Dates and Times as timestamps. |
| 390 | char d1[] = "2012-01-20"; |
| 391 | char d2[] = "1990-10-20"; |
nothing calls this directly
no test coverage detected