/*-----------------------------------------------------------------------*
 * filename - setdate.c
 *
 * function(s)
 *        setdate - sets system date
 *        settime - sets system time
 *-----------------------------------------------------------------------*/

/*
 *      C/C++ Run Time Library - Version 6.0
 *
 *      Copyright (c) 1991, 1993 by Borland International
 *      All Rights Reserved.
 *
 */

#include <ntbc.h>

#include <dos.h>
#include <errno.h>
#include <_io.h>

/*-----------------------------------------------------------------------*

Name            setdate - sets system date

Usage           #include <dos.h>
                void setdate(struct date *dateblk);

Prototype in    dos.h

Description     see getdate

*------------------------------------------------------------------------*/

void _RTLENTRY _EXPFUNC setdate(struct date *datep)
{
    SYSTEMTIME d;

    /* Get current date/time so that the time will be preserved.
     */
    GetSystemTime(&d);

    /* Convert the date structure to a system SYSTEMTIME and set the date.
     */
    d.wDay = datep->da_day;
    d.wMonth = datep->da_mon;
    d.wYear = datep->da_year;
    if (SetSystemTime(&d) != TRUE)
        __NTerror();
}

/*-----------------------------------------------------------------------*

Name            settime - sets system time

Usage           #include <dos.h>
                void settime(struct time *timeblk);

Prototype in    dos.h

Description     see gettime

*------------------------------------------------------------------------*/

void _RTLENTRY _EXPFUNC settime(struct time *timep)
{
    SYSTEMTIME d;

    /* Get current time so that the date and year will be preserved.
     */
    GetSystemTime(&d);

    /* Convert the dostime_t structure to an system SYSTEMTIME and set the time.
     */
    d.wHour = timep->ti_hour;
    d.wMinute = timep->ti_min;
    d.wSecond = timep->ti_sec;
    d.wMilliseconds = timep->ti_hund * 10;
    if (SetSystemTime(&d) != TRUE)
        __NTerror();
}

