<commit_before>/*
 * Copyright(c) Records For Living, Inc. 2004-2012.  All rights reserved
 */
#include    "Stroika/Foundation/StroikaPreComp.h"

#if     qCompilerAndStdLib_Supports_stdchrono
#include    <chrono>
#endif

#include    <iostream>
#include    <sstream>

#include    "Stroika/Foundation/Debug/Assertions.h"
#include    "Stroika/Foundation/Debug/Trace.h"
#include    "Stroika/Foundation/Execution/Sleep.h"
#include    "Stroika/Foundation/Time/Date.h"
#include    "Stroika/Foundation/Time/DateTime.h"
#include    "Stroika/Foundation/Time/Duration.h"
#include    "Stroika/Foundation/Time/Realtime.h"

#include    "../TestHarness/TestHarness.h"


using   namespace   Stroika::Foundation;
using   namespace   Stroika::Foundation::Time;

using   Stroika::Foundation::Debug::TraceContextBumper;



namespace   {

    void    Test_1_TestTickCountGrowsMonotonically_ ()
    {
        DurationSecondsType start   =   Time::GetTickCount ();
        Execution::Sleep (0.1);
        VerifyTestResult (start <= Time::GetTickCount ());
    }

}


namespace   {

    void    Test_2_TestTimeOfDay_ ()
    {
        {
            TimeOfDay   t;
            VerifyTestResult (t.empty ());
            TimeOfDay   t2 (2);
            VerifyTestResult (t < t2);
            VerifyTestResult (t.GetAsSecondsCount () == 0);
            VerifyTestResult (not t2.empty ());
            VerifyTestResult (t.Format ().empty ());
            VerifyTestResult (not t2.Format ().empty ());
            VerifyTestResult (t2.GetHours () == 0);
            VerifyTestResult (t2.GetMinutes () == 0);
            VerifyTestResult (t2.GetSeconds () == 2);
        }
        {
            TimeOfDay   t2 (5 * 60 * 60 + 3 * 60 + 49);
            VerifyTestResult (t2.GetHours () == 5);
            VerifyTestResult (t2.GetMinutes () == 3);
            VerifyTestResult (t2.GetSeconds () == 49);
        }
        {
            TimeOfDay   t2 (25 * 60 * 60);
            VerifyTestResult (t2.GetHours () == 23);
            VerifyTestResult (t2.GetMinutes () == 59);
            VerifyTestResult (t2.GetSeconds () == 59);
            VerifyTestResult (t2 == TimeOfDay::kMax);
        }
        {
            VerifyTestResult (TimeOfDay::Parse (L"3pm", locale::classic ()).GetAsSecondsCount () == 15 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"3am", locale::classic ()).GetAsSecondsCount () == 3 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"3:00", locale::classic ()).GetAsSecondsCount () == 3 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"16:00", locale::classic ()).GetAsSecondsCount () == 16 * 60 * 60);
        }
        {
            // Not sure these should ALWAYS work in any locale. Probably not. But any locale I'd test in??? Maybe... Good for starters anyhow...
            //      -- LGP 2011-10-08
            VerifyTestResult (TimeOfDay::Parse (L"3pm", TimeOfDay::PrintFormat::eCurrentLocale).GetAsSecondsCount () == 15 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"3am", TimeOfDay::PrintFormat::eCurrentLocale).GetAsSecondsCount () == 3 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"3:00", TimeOfDay::PrintFormat::eCurrentLocale).GetAsSecondsCount () == 3 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"16:00", TimeOfDay::PrintFormat::eCurrentLocale).GetAsSecondsCount () == 16 * 60 * 60);
        }

        {
#if     qPlatform_Windows
            const   LCID    kUS_ENGLISH_LOCALE  =   MAKELCID (MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
#endif
            TimeOfDay   threePM =   TimeOfDay::Parse (L"3pm", locale::classic ());
#if     qPlatform_Windows
            VerifyTestResult (threePM.Format (kUS_ENGLISH_LOCALE) == L"3 PM");
#endif
            //VerifyTestResult (threePM.Format (locale::classic ()) == L"3 PM");
            VerifyTestResult (threePM.Format (locale::classic ()) == L"15:00:00");  // UGH!!!
        }

    }

}


namespace   {
    void    VERIFY_ROUNDTRIP_XML_ (const Date& d)
    {
        VerifyTestResult (Date::Parse (d.Format (Date::PrintFormat::eXML), Date::PrintFormat::eXML) == d);
    }

    void    Test_3_TestDate_ ()
    {
        {
            Date    d (Year (1903), MonthOfYear::eApril, DayOfMonth (4));
            VerifyTestResult (d.Format (Date::PrintFormat::eXML) == L"1903-04-04");
            VERIFY_ROUNDTRIP_XML_ (d);
            d.AddDays (4);
            VERIFY_ROUNDTRIP_XML_ (d);
            VerifyTestResult (d.Format (Date::PrintFormat::eXML) == L"1903-04-08");
            d.AddDays (-4);
            VERIFY_ROUNDTRIP_XML_ (d);
            VerifyTestResult (d.Format (Date::PrintFormat::eXML) == L"1903-04-04");
        }
        {
            Date    d   =   Date::Parse (L"09/14/1752", locale::classic ());
            VerifyTestResult (not d.empty ());
            VerifyTestResult (d == Date::kMin);
            VerifyTestResult (d.Format (Date::PrintFormat::eXML) == L"1752-09-14"); // xml cuz otherwise we get confusion over locale - COULD use hardwired US locale at some point?
        }
        {<commit_msg>fixed date regression test to accomodate recent change in meaning of AddDays()<commit_after>/*
 * Copyright(c) Records For Living, Inc. 2004-2012.  All rights reserved
 */
#include    "Stroika/Foundation/StroikaPreComp.h"

#if     qCompilerAndStdLib_Supports_stdchrono
#include    <chrono>
#endif

#include    <iostream>
#include    <sstream>

#include    "Stroika/Foundation/Debug/Assertions.h"
#include    "Stroika/Foundation/Debug/Trace.h"
#include    "Stroika/Foundation/Execution/Sleep.h"
#include    "Stroika/Foundation/Time/Date.h"
#include    "Stroika/Foundation/Time/DateTime.h"
#include    "Stroika/Foundation/Time/Duration.h"
#include    "Stroika/Foundation/Time/Realtime.h"

#include    "../TestHarness/TestHarness.h"


using   namespace   Stroika::Foundation;
using   namespace   Stroika::Foundation::Time;

using   Stroika::Foundation::Debug::TraceContextBumper;



namespace   {

    void    Test_1_TestTickCountGrowsMonotonically_ ()
    {
        DurationSecondsType start   =   Time::GetTickCount ();
        Execution::Sleep (0.1);
        VerifyTestResult (start <= Time::GetTickCount ());
    }

}


namespace   {

    void    Test_2_TestTimeOfDay_ ()
    {
        {
            TimeOfDay   t;
            VerifyTestResult (t.empty ());
            TimeOfDay   t2 (2);
            VerifyTestResult (t < t2);
            VerifyTestResult (t.GetAsSecondsCount () == 0);
            VerifyTestResult (not t2.empty ());
            VerifyTestResult (t.Format ().empty ());
            VerifyTestResult (not t2.Format ().empty ());
            VerifyTestResult (t2.GetHours () == 0);
            VerifyTestResult (t2.GetMinutes () == 0);
            VerifyTestResult (t2.GetSeconds () == 2);
        }
        {
            TimeOfDay   t2 (5 * 60 * 60 + 3 * 60 + 49);
            VerifyTestResult (t2.GetHours () == 5);
            VerifyTestResult (t2.GetMinutes () == 3);
            VerifyTestResult (t2.GetSeconds () == 49);
        }
        {
            TimeOfDay   t2 (25 * 60 * 60);
            VerifyTestResult (t2.GetHours () == 23);
            VerifyTestResult (t2.GetMinutes () == 59);
            VerifyTestResult (t2.GetSeconds () == 59);
            VerifyTestResult (t2 == TimeOfDay::kMax);
        }
        {
            VerifyTestResult (TimeOfDay::Parse (L"3pm", locale::classic ()).GetAsSecondsCount () == 15 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"3am", locale::classic ()).GetAsSecondsCount () == 3 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"3:00", locale::classic ()).GetAsSecondsCount () == 3 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"16:00", locale::classic ()).GetAsSecondsCount () == 16 * 60 * 60);
        }
        {
            // Not sure these should ALWAYS work in any locale. Probably not. But any locale I'd test in??? Maybe... Good for starters anyhow...
            //      -- LGP 2011-10-08
            VerifyTestResult (TimeOfDay::Parse (L"3pm", TimeOfDay::PrintFormat::eCurrentLocale).GetAsSecondsCount () == 15 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"3am", TimeOfDay::PrintFormat::eCurrentLocale).GetAsSecondsCount () == 3 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"3:00", TimeOfDay::PrintFormat::eCurrentLocale).GetAsSecondsCount () == 3 * 60 * 60);
            VerifyTestResult (TimeOfDay::Parse (L"16:00", TimeOfDay::PrintFormat::eCurrentLocale).GetAsSecondsCount () == 16 * 60 * 60);
        }

        {
#if     qPlatform_Windows
            const   LCID    kUS_ENGLISH_LOCALE  =   MAKELCID (MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
#endif
            TimeOfDay   threePM =   TimeOfDay::Parse (L"3pm", locale::classic ());
#if     qPlatform_Windows
            VerifyTestResult (threePM.Format (kUS_ENGLISH_LOCALE) == L"3 PM");
#endif
            //VerifyTestResult (threePM.Format (locale::classic ()) == L"3 PM");
            VerifyTestResult (threePM.Format (locale::classic ()) == L"15:00:00");  // UGH!!!
        }

    }

}


namespace   {
    void    VERIFY_ROUNDTRIP_XML_ (const Date& d)
    {
        VerifyTestResult (Date::Parse (d.Format (Date::PrintFormat::eXML), Date::PrintFormat::eXML) == d);
    }

    void    Test_3_TestDate_ ()
    {
        {
            Date    d (Year (1903), MonthOfYear::eApril, DayOfMonth (4));
            VerifyTestResult (d.Format (Date::PrintFormat::eXML) == L"1903-04-04");
            VERIFY_ROUNDTRIP_XML_ (d);
            d = d.AddDays (4);
            VERIFY_ROUNDTRIP_XML_ (d);
            VerifyTestResult (d.Format (Date::PrintFormat::eXML) == L"1903-04-08");
            d = d.AddDays (-4);
            VERIFY_ROUNDTRIP_XML_ (d);
            VerifyTestResult (d.Format (Date::PrintFormat::eXML) == L"1903-04-04");
        }
        {
            Date    d   =   Date::Parse (L"09/14/1752", locale::classic ());
            VerifyTestResult (not d.empty ());
            VerifyTestResult (d == Date::kMin);
            VerifyTestResult (d.Format (Date::PrintFormat::eXML) == L"1752-09-14"); // xml cuz otherwise we get confusion over locale - COULD use hardwired US locale at some point?
        }
        {
{'fraction_non_alphanumeric': 0.1392120441880927, 'fraction_numerical': 0.036367191318799494, 'mean_word_length': 2.435191403626595, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2046083', 'n_tokens_mistral': 3506, 'n_tokens_neox': 3295, 'n_words': 647}