<commit_before>//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include <nanoHAL.h>
#include <nanoHAL_Types.h>
#include <nanoCLR_Types.h>
#include <nanoHAL_Time.h>
#include <target_platform.h>
#include <Esp32_os.h>

// Returns the current date time from the RTC 
uint64_t  HAL_Time_CurrentDateTime(bool datePartOnly)
{
    SYSTEMTIME st; 
 
    struct timeval tv;

    gettimeofday(&tv, NULL);

    // Convert from Unix time(year since 1900) to SYSTEMTIME(Years since 1601)
    int64_t time = ((int64_t)tv.tv_sec * (int64_t)TIME_CONVERSION__TO_SECONDS) + ((int64_t)tv.tv_usec * (int64_t)TIME_CONVERSION__TO_MILLISECONDS ) + TIME_UNIX_EPOCH_AS_TICKS;

    HAL_Time_ToSystemTime(time, &st );

    // zero 'time' fields if date part only is required
    if(datePartOnly)
    {
        st.wMilliseconds = 0;
        st.wSecond = 0;
        st.wMinute = 0;
        st.wHour = 0;
    }

    return HAL_Time_ConvertFromSystemTime( &st );
};

void HAL_Time_SetUtcTime(uint64_t utcTime)
{
    SYSTEMTIME systemTime;

    HAL_Time_ToSystemTime(utcTime, &systemTime);

    struct tm newTime;

    newTime.tm_year = systemTime.wYear - 1900;      // years since 1900
    newTime.tm_mon = systemTime.wMonth - 1;         // months since January 0-11
    newTime.tm_mday = systemTime.wDay;              // day of the month 1-31
    newTime.tm_wday = systemTime.wDayOfWeek;        // days since Sunday 0-6
    newTime.tm_hour = (uint32_t)systemTime.wHour;   // hours since midnight 0-23
    newTime.tm_min = (uint32_t)systemTime.wMinute;  // minutes after the hour 0-59<commit_msg>Fix milli secs conversion (#1384)<commit_after>//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include <nanoHAL.h>
#include <nanoHAL_Types.h>
#include <nanoCLR_Types.h>
#include <nanoHAL_Time.h>
#include <target_platform.h>
#include <Esp32_os.h>

#define TIME_CONVERSION__TO_USECS	10

// Returns the current date time from the RTC 
uint64_t  HAL_Time_CurrentDateTime(bool datePartOnly)
{
    SYSTEMTIME st; 
 
    struct timeval tv;

    gettimeofday(&tv, NULL);

    // Convert from Unix time(year since 1900) to SYSTEMTIME(Years since 1601)
	int64_t time = ((int64_t)tv.tv_sec * (int64_t)TIME_CONVERSION__TO_SECONDS) + ((int64_t)tv.tv_usec * (int64_t)TIME_CONVERSION__TO_USECS) + TIME_UNIX_EPOCH_AS_TICKS;

    HAL_Time_ToSystemTime(time, &st );

    // zero 'time' fields if date part only is required
    if(datePartOnly)
    {
        st.wMilliseconds = 0;
        st.wSecond = 0;
        st.wMinute = 0;
        st.wHour = 0;
    }

    return HAL_Time_ConvertFromSystemTime( &st );
};

void HAL_Time_SetUtcTime(uint64_t utcTime)
{
    SYSTEMTIME systemTime;

    HAL_Time_ToSystemTime(utcTime, &systemTime);

    struct tm newTime;

    newTime.tm_year = systemTime.wYear - 1900;      // years since 1900
    newTime.tm_mon = systemTime.wMonth - 1;         // months since January 0-11
    newTime.tm_mday = systemTime.wDay;              // day of the month 1-31
    newTime.tm_wday = systemTime.wDayOfWeek;        // days since Sunday 0-6
    newTime.tm_hour = (uint32_t)systemTime.wHour;   // hours since midnight 0-23
    newTime.tm_min = (uint32_t)systemTime.wMinute;  // minutes after the hour 0-59
{'fraction_non_alphanumeric': 0.09895678092399404, 'fraction_numerical': 0.03695976154992549, 'mean_word_length': 3.2107904642409033, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2652818', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1191, 'n_words': 282}