aboutsummaryrefslogtreecommitdiffstats
path: root/yt/yt/client/unittests/time_text_ut.cpp
blob: a8b5d1a10a40ce6a933cc15bbc447440349fed79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <yt/yt/core/test_framework/framework.h>

#include <yt/yt/client/complex_types/time_text.h>

namespace NYT::NComplexTypes {

using namespace NTableClient;

////////////////////////////////////////////////////////////////////////////////

TEST(TimeConverter, Correct)
{
    EXPECT_EQ(BinaryTimeFromText("2021-09-03", ESimpleLogicalValueType::Date), 18873U);

    EXPECT_EQ(BinaryTimeFromText("2021-09-03T10:12:41Z", ESimpleLogicalValueType::Datetime), 1630663961U);

    EXPECT_EQ(BinaryTimeFromText("2021-09-03T10:12:41Z", ESimpleLogicalValueType::Timestamp), 1630663961000000ULL);
    EXPECT_EQ(BinaryTimeFromText("2021-09-03T10:12:41.1Z", ESimpleLogicalValueType::Timestamp), 1630663961100000ULL);
    EXPECT_EQ(BinaryTimeFromText("2021-09-03T10:12:41.123456Z", ESimpleLogicalValueType::Timestamp), 1630663961123456ULL);
}

TEST(TimeConverter, InvalidLength)
{
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09", ESimpleLogicalValueType::Date),
        "Invalid date string length");
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03T", ESimpleLogicalValueType::Date),
        "Invalid date string length");
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03T10:12:41Z", ESimpleLogicalValueType::Date),
        "Invalid date string length");
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03T10:12:41.1Z", ESimpleLogicalValueType::Date),
        "Invalid date string length");

    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03", ESimpleLogicalValueType::Datetime),
        "Invalid date string length");
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03T10:12:41", ESimpleLogicalValueType::Datetime),
        "Invalid date string length");
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03T10:12:41.1Z", ESimpleLogicalValueType::Datetime),
        "Invalid date string length");

    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03", ESimpleLogicalValueType::Timestamp),
        "Invalid date string length");
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03T10:12:41.1234567Z", ESimpleLogicalValueType::Timestamp),
        "Invalid date string length");
}

TEST(TimeConverter, InvalidFormat)
{
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-3T", ESimpleLogicalValueType::Date),
        "Could not parse date");
    EXPECT_THROW_WITH_SUBSTRING(
        BinaryTimeFromText("2021-09-03T23:59:59H", ESimpleLogicalValueType::Datetime),
        "Could not parse date");
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NComplexTypes