• Re: New clock !

    From Bonita Montero@3:633/10 to All on Sun Sep 7 19:28:58 2025
    XPost: comp.lang.c
    From: Bonita.Montero@gmail.com

    Oh, wrong group.

    Am 07.09.2025 um 18:57 schrieb Bonita Montero:
    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
        #include <Windows.h>
    #elif defined(__unix__)
        #include <time.h>
    #else
        #error dasdasd
    #endif

    struct win_time
    {
        using rep = int64_t;
        using period = std::ratio<1, 10000000>;
        using duration = std::chrono::duration<rep, period>;
        using time_point = std::chrono::time_point<win_time, duration>;
        static time_point now() noexcept;
        static constexpr bool is_steady = true;
    private:
        static constexpr int64_t UNIX_START = 116444736000000000;
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
        FILETIME ft;
        GetSystemTimePreciseAsFileTime( &ft );
        return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
    #elif defined(__unix__)
        timespec ts;
        clock_gettime( CLOCK_REALTIME, &ts );
        return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec * 10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
    #endif
    }

    What does this do ?

    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
    #include <Windows.h>
    #elif defined(__unix__)
    #include <time.h>
    #else
    #error dasdasd
    #endif

    struct win_time
    {
    using rep = int64_t;
    using period = std::ratio<1, 10000000>;
    using duration = std::chrono::duration<rep, period>;
    using time_point = std::chrono::time_point<win_time, duration>;
    static time_point now() noexcept;
    static constexpr bool is_steady = false;
    private:
    static constexpr time_point UNIX_START = time_point( duration( 116444736000000000 ) );
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
    FILETIME ft;
    GetSystemTimePreciseAsFileTime( &ft );
    return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
    #elif defined(__unix__)
    using namespace std::chrono;
    timespec ts;
    clock_gettime( CLOCK_REALTIME, &ts );
    return UNIX_START + duration_cast<win_time::duration>( seconds( ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
    #endif
    }

    --- SoupGate-Linux v1.05
    * Origin: ---:- FTN<->Usenet Gate -:--- (3:633/10)
  • From wij@3:633/10 to Bonita Montero on Mon Sep 8 05:04:10 2025
    From: wyniijj5@gmail.com

    On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
    Oh, wrong group.

    Am 07.09.2025 um 18:57 schrieb Bonita Montero:
    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
         #include <Windows.h>
    #elif defined(__unix__)
         #include <time.h>
    #else
         #error dasdasd
    #endif

    struct win_time
    {
         using rep = int64_t;
         using period = std::ratio<1, 10000000>;
         using duration = std::chrono::duration<rep, period>;
         using time_point = std::chrono::time_point<win_time, duration>;      static time_point now() noexcept;
         static constexpr bool is_steady = true;
    private:
         static constexpr int64_t UNIX_START = 116444736000000000;
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
         FILETIME ft;
         GetSystemTimePreciseAsFileTime( &ft );
         return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
    #elif defined(__unix__)
         timespec ts;
         clock_gettime( CLOCK_REALTIME, &ts );
         return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec * 10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
    #endif
    }

    What does this do ?

    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
    #include <Windows.h>
    #elif defined(__unix__)
    #include <time.h>
    #else
    #error dasdasd
    #endif

    struct win_time
    {
    using rep = int64_t;
    using period = std::ratio<1, 10000000>;
    using duration = std::chrono::duration<rep, period>;
    using time_point = std::chrono::time_point<win_time, duration>;
    static time_point now() noexcept;
    static constexpr bool is_steady = false;
    private:
    static constexpr time_point UNIX_START = time_point( duration( 116444736000000000 ) );
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
    FILETIME ft;
    GetSystemTimePreciseAsFileTime( &ft );
    return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
    #elif defined(__unix__)
    using namespace std::chrono;
    timespec ts;
    clock_gettime( CLOCK_REALTIME, &ts );
    return UNIX_START + duration_cast<win_time::duration>( seconds( ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
    #endif
    }

    Typical problems of C++ program are demonstrated.
    But first, what the purpose of win_time?

    --- SoupGate-Linux v1.05
    * Origin: ---:- FTN<->Usenet Gate -:--- (3:633/10)
  • From Bonita Montero@3:633/10 to All on Sun Sep 7 23:22:56 2025
    From: Bonita.Montero@gmail.com

    Am 07.09.2025 um 23:04 schrieb wij:
    On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
    Oh, wrong group.

    Am 07.09.2025 um 18:57 schrieb Bonita Montero:
    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
         #include <Windows.h>
    #elif defined(__unix__)
         #include <time.h>
    #else
         #error dasdasd
    #endif

    struct win_time
    {
         using rep = int64_t;
         using period = std::ratio<1, 10000000>;
         using duration = std::chrono::duration<rep, period>;
         using time_point = std::chrono::time_point<win_time, duration>; >>>      static time_point now() noexcept;
         static constexpr bool is_steady = true;
    private:
         static constexpr int64_t UNIX_START = 116444736000000000;
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
         FILETIME ft;
         GetSystemTimePreciseAsFileTime( &ft );
         return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | >>> ft.dwLowDateTime ) );
    #elif defined(__unix__)
         timespec ts;
         clock_gettime( CLOCK_REALTIME, &ts );
         return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec * >>> 10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
    #endif
    }

    What does this do ?

    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
    #include <Windows.h>
    #elif defined(__unix__)
    #include <time.h>
    #else
    #error dasdasd
    #endif

    struct win_time
    {
    using rep = int64_t;
    using period = std::ratio<1, 10000000>;
    using duration = std::chrono::duration<rep, period>;
    using time_point = std::chrono::time_point<win_time, duration>;
    static time_point now() noexcept;
    static constexpr bool is_steady = false;
    private:
    static constexpr time_point UNIX_START = time_point( duration(
    116444736000000000 ) );
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
    FILETIME ft;
    GetSystemTimePreciseAsFileTime( &ft );
    return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
    ft.dwLowDateTime ) );
    #elif defined(__unix__)
    using namespace std::chrono;
    timespec ts;
    clock_gettime( CLOCK_REALTIME, &ts );
    return UNIX_START + duration_cast<win_time::duration>( seconds(
    ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
    #endif
    }

    Typical problems of C++ program are demonstrated.
    But first, what the purpose of win_time?


    Problems with auch a few lines of code - idiot !

    --- SoupGate-Linux v1.05
    * Origin: ---:- FTN<->Usenet Gate -:--- (3:633/10)
  • From wij@3:633/10 to Bonita Montero on Mon Sep 8 19:46:52 2025
    From: wyniijj5@gmail.com

    On Sun, 2025-09-07 at 23:22 +0200, Bonita Montero wrote:
    Am 07.09.2025 um 23:04 schrieb wij:
    On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
    Oh, wrong group.

    Am 07.09.2025 um 18:57 schrieb Bonita Montero:
    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
          #include <Windows.h>
    #elif defined(__unix__)
          #include <time.h>
    #else
          #error dasdasd
    #endif

    struct win_time
    {
          using rep = int64_t;
          using period = std::ratio<1, 10000000>;
          using duration = std::chrono::duration<rep, period>;       using time_point = std::chrono::time_point<win_time, duration>;
          static time_point now() noexcept;
          static constexpr bool is_steady = true;
    private:
          static constexpr int64_t UNIX_START = 116444736000000000;
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
          FILETIME ft;
          GetSystemTimePreciseAsFileTime( &ft );
          return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
    ft.dwLowDateTime ) );
    #elif defined(__unix__)
          timespec ts;
          clock_gettime( CLOCK_REALTIME, &ts );
          return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec *
    10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
    #endif
    }

    What does this do ?

    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
    #include <Windows.h>
    #elif defined(__unix__)
    #include <time.h>
    #else
    #error dasdasd
    #endif

    struct win_time
    {
    using rep = int64_t;
    using period = std::ratio<1, 10000000>;
    using duration = std::chrono::duration<rep, period>;
    using time_point = std::chrono::time_point<win_time, duration>;
    static time_point now() noexcept;
    static constexpr bool is_steady = false;
    private:
    static constexpr time_point UNIX_START = time_point( duration( 116444736000000000 ) );
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
    FILETIME ft;
    GetSystemTimePreciseAsFileTime( &ft );
    return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
    #elif defined(__unix__)
    using namespace std::chrono;
    timespec ts;
    clock_gettime( CLOCK_REALTIME, &ts );
    return UNIX_START + duration_cast<win_time::duration>( seconds( ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
    #endif
    }

    Typical problems of C++ program are demonstrated.
    But first, what the purpose of win_time?


    Problems with auch a few lines of code - idiot !

    You simplified the problem you were dealing with, not really the programming.

    Also, from my always-check-errors policy, you missed the checking for errors  and 'noexcept' of now() is problematic.

    --- SoupGate-Linux v1.05
    * Origin: Dragon's Lair ---:- FidoNet<>Usenet Gateway -:--- (3:633/10)
  • From Bonita Montero@3:633/10 to All on Wed Sep 10 00:05:38 2025
    From: Bonita.Montero@gmail.com

    Am 08.09.2025 um 13:46 schrieb wij:
    On Sun, 2025-09-07 at 23:22 +0200, Bonita Montero wrote:
    Am 07.09.2025 um 23:04 schrieb wij:
    On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
    Oh, wrong group.

    Am 07.09.2025 um 18:57 schrieb Bonita Montero:
    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
          #include <Windows.h>
    #elif defined(__unix__)
          #include <time.h>
    #else
          #error dasdasd
    #endif

    struct win_time
    {
          using rep = int64_t;
          using period = std::ratio<1, 10000000>;
          using duration = std::chrono::duration<rep, period>;
          using time_point = std::chrono::time_point<win_time, duration>;
          static time_point now() noexcept;
          static constexpr bool is_steady = true;
    private:
          static constexpr int64_t UNIX_START = 116444736000000000; >>>>> };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
          FILETIME ft;
          GetSystemTimePreciseAsFileTime( &ft );
          return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
    ft.dwLowDateTime ) );
    #elif defined(__unix__)
          timespec ts;
          clock_gettime( CLOCK_REALTIME, &ts );
          return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec *
    10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
    #endif
    }

    What does this do ?

    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
    #include <Windows.h>
    #elif defined(__unix__)
    #include <time.h>
    #else
    #error dasdasd
    #endif

    struct win_time
    {
    using rep = int64_t;
    using period = std::ratio<1, 10000000>;
    using duration = std::chrono::duration<rep, period>;
    using time_point = std::chrono::time_point<win_time, duration>;
    static time_point now() noexcept;
    static constexpr bool is_steady = false;
    private:
    static constexpr time_point UNIX_START = time_point( duration(
    116444736000000000 ) );
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
    FILETIME ft;
    GetSystemTimePreciseAsFileTime( &ft );
    return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
    ft.dwLowDateTime ) );
    #elif defined(__unix__)
    using namespace std::chrono;
    timespec ts;
    clock_gettime( CLOCK_REALTIME, &ts );
    return UNIX_START + duration_cast<win_time::duration>( seconds(
    ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
    #endif
    }

    Typical problems of C++ program are demonstrated.
    But first, what the purpose of win_time?


    Problems with auch a few lines of code - idiot !

    You simplified the problem you were dealing with, not really the programming.

    Also, from my always-check-errors policy, you missed the checking for errors and 'noexcept' of now() is problematic.


    ::now() is noexcept with C++ in general. So if C++ itself isn't dealing
    with errors fot that actually never fails. AnGetSystemTimePreciseAs
    FileTime() has no error code at all.

    --- SoupGate-Linux v1.05
    * Origin: Dragon's Lair ---:- FidoNet<>Usenet Gateway -:--- (3:633/10)
  • From wij@3:633/10 to Bonita Montero on Thu Sep 11 10:08:11 2025
    From: wyniijj5@gmail.com

    On Wed, 2025-09-10 at 00:05 +0200, Bonita Montero wrote:
    Am 08.09.2025 um 13:46 schrieb wij:
    On Sun, 2025-09-07 at 23:22 +0200, Bonita Montero wrote:
    Am 07.09.2025 um 23:04 schrieb wij:
    On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
    Oh, wrong group.

    Am 07.09.2025 um 18:57 schrieb Bonita Montero:
    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
           #include <Windows.h>
    #elif defined(__unix__)
           #include <time.h>
    #else
           #error dasdasd
    #endif

    struct win_time
    {
           using rep = int64_t;
           using period = std::ratio<1, 10000000>;
           using duration = std::chrono::duration<rep, period>;        using time_point = std::chrono::time_point<win_time, duration>;
           static time_point now() noexcept;
           static constexpr bool is_steady = true;
    private:
           static constexpr int64_t UNIX_START = 116444736000000000;
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
           FILETIME ft;
           GetSystemTimePreciseAsFileTime( &ft );
           return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
    ft.dwLowDateTime ) );
    #elif defined(__unix__)
           timespec ts;
           clock_gettime( CLOCK_REALTIME, &ts );
           return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec *
    10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
    #endif
    }

    What does this do ?

    #pragma once
    #include <cstdint>
    #include <chrono>
    #if defined(_WIN32)
    #include <Windows.h>
    #elif defined(__unix__)
    #include <time.h>
    #else
    #error dasdasd
    #endif

    struct win_time
    {
    using rep = int64_t;
    using period = std::ratio<1, 10000000>;
    using duration = std::chrono::duration<rep, period>;
    using time_point = std::chrono::time_point<win_time, duration>;
    static time_point now() noexcept;
    static constexpr bool is_steady = false;
    private:
    static constexpr time_point UNIX_START = time_point( duration( 116444736000000000 ) );
    };

    inline win_time::time_point win_time::now() noexcept
    {
    #if defined(_WIN32)
    FILETIME ft;
    GetSystemTimePreciseAsFileTime( &ft );
    return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
    ft.dwLowDateTime ) );
    #elif defined(__unix__)
    using namespace std::chrono;
    timespec ts;
    clock_gettime( CLOCK_REALTIME, &ts );
    return UNIX_START + duration_cast<win_time::duration>( seconds( ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
    #endif
    }

    Typical problems of C++ program are demonstrated.
    But first, what the purpose of win_time?


    Problems with auch a few lines of code - idiot !

    You simplified the problem you were dealing with, not really the programming.

    Also, from my always-check-errors policy, you missed the checking for errors
    and 'noexcept' of now() is problematic.


    ::now() is noexcept with C++ in general. So if C++ itself isn't dealing
    with errors fot that actually never fails. AnGetSystemTimePreciseAs FileTime() has no error code at all.

    I won't say too much.
    Your implement contains possible abnormal termination.

    --- SoupGate-Linux v1.05
    * Origin: Dragon's Lair ---:- FidoNet<>Usenet Gateway -:--- (3:633/10)
  • From Bonita Montero@3:633/10 to All on Thu Sep 11 05:33:06 2025
    From: Bonita.Montero@gmail.com

    Am 11.09.2025 um 04:08 schrieb wij:

    I won't say too much.
    Your implement contains possible abnormal termination.

    The implementation of all clocks of the runtime also.

    --- SoupGate-Linux v1.05
    * Origin: Dragon's Lair ---:- FidoNet<>Usenet Gateway -:--- (3:633/10)
  • From Bonita Montero@3:633/10 to All on Fri Oct 10 03:26:14 2025
    This is the current code to convert a time_point with 100ns-ticks
    since 1.1.1601 00:00:00.0 to a date in Gregorian or Julian calendar.

    template<bool Gregorian>
    void date_1601<Gregorian>::from_time_point( time_point timePoint ) noexcept
    {
    uint64_t tsCalc = timePoint.time_since_epoch().count();
    bool leapYear = false;
    constexpr int64_t Y4S = FOUR_YEARS_W_LY;
    int y400 = 0, y100 = 0, y4, yMod4, patch = 0;
    bool leapQuad = true;
    if constexpr( Gregorian )
    {
    constexpr int64_t Y400S = FOUR_HUNDRED_YEARS;
    if( (int64_t)tsCalc >= -(int64_t)LEAP_YEAR )
    {
    if( (int64_t)(tsCalc + LEAP_YEAR) < (int64_t)tsCalc )
    {
    tsCalc -= FOUR_HUNDRED_YEARS;
    patch = 400;
    }
    tsCalc += LEAP_YEAR;
    y400 += (int)(tsCalc / FOUR_HUNDRED_YEARS);
    }
    else
    {
    tsCalc += LEAP_YEAR;
    if( (int64_t)tsCalc <= -Y400S )
    {
    tsCalc += FOUR_HUNDRED_YEARS;
    patch = -400;
    }
    y400 += (int)((int64_t)(tsCalc - (Y400S - 1)) / Y400S);
    }
    tsCalc -= y400 * Y400S;
    if( tsCalc >= FIRST_CENTURY )
    {
    y100 = (int)((tsCalc - FIRST_CENTURY) / REMAINING_CENUTRIES); // 0 ... 2
    tsCalc -= FIRST_CENTURY + y100++ * REMAINING_CENUTRIES; // -> 1 ... 3
    if( tsCalc >= FOUR_YEARS_WO_LY )
    {
    y4 = (int)((tsCalc - FOUR_YEARS_WO_LY) / FOUR_YEARS_W_LY); // 0 ... 23
    tsCalc -= FOUR_YEARS_WO_LY + y4++ * FOUR_YEARS_W_LY; // -> 1 ... 24
    }
    else
    {
    y4 = 0;
    yMod4 = (int)(tsCalc / NON_LEAP_YEAR);
    tsCalc -= yMod4 * NON_LEAP_YEAR;
    leapQuad = false;
    }
    }
    else
    {
    y100 = 0;
    y4 = (int)(tsCalc / FOUR_YEARS_W_LY);
    tsCalc -= y4 * FOUR_YEARS_W_LY;
    }
    }
    else
    {
    if( (int64_t)tsCalc >= -(int64_t)JULIAN_ZERO_1600 )
    {
    if( (int64_t)(tsCalc + JULIAN_ZERO_1600) < (int64_t)tsCalc )
    {
    tsCalc -= FOUR_YEARS_W_LY;
    patch = 4;
    }
    tsCalc += JULIAN_ZERO_1600;
    y4 = (int)(tsCalc / FOUR_YEARS_W_LY);
    }
    else
    {
    tsCalc += JULIAN_ZERO_1600;
    if( (int64_t)tsCalc <= -Y4S )
    {
    tsCalc += FOUR_YEARS_W_LY;
    patch = -4;
    }
    y4 = (int)((int64_t)(tsCalc - (Y4S - 1)) / Y4S);
    }
    tsCalc -= y4 * Y4S;
    }
    if( leapQuad )
    if( leapYear = tsCalc < LEAP_YEAR; !leapYear )
    {
    tsCalc -= LEAP_YEAR;
    yMod4 = (int)(tsCalc / NON_LEAP_YEAR); // 0 ... 2
    tsCalc -= yMod4++ * NON_LEAP_YEAR; // -> 1 ... 3
    }
    else
    yMod4 = 0;
    year = (int16_t)(1600 + 400 * y400 + 100 * y100 + 4 * y4 + yMod4 + patch);
    {
    uint16_t yDay = (uint16_t)(tsCalc / DAY);
    tsCalc %= DAY;
    span dualDaysAfterYear( g_daysAfterYear );
    span daysAfterYear( dualDaysAfterYear[leapYear] );
    month = 0;
    for( ; yDay >= daysAfterYear[month + 1]; ++month );
    assert(month < 12);
    day = yDay - daysAfterYear[month] + 1;
    ++month;
    }
    hour = (uint8_t)(tsCalc / HOUR);
    tsCalc %= HOUR;
    minute = (uint8_t)(tsCalc / MINUTE);
    tsCalc %= MINUTE;
    second = (uint8_t)((uint32_t)tsCalc / (uint32_t)SECOND);
    ticks = (uint32_t)tsCalc % (uint32_t)SECOND;
    weekday = get_weekday( timePoint );
    }

    --- PyGate Linux v1.0
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)