/* WARNING: This file was generated by dkct. Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4ctime.ctr */ /* Copyright (C) 2015-2017, Dirk Krause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above opyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @file dk4ctime.c The dk4ctime module. */ #line 131 "dk4ctime.ctr" #include "dk4conf.h" #include "dk4types.h" #include "dk4ctime.h" #ifndef DK4REC22_H_INCLUDED #include "dk4rec22.h" #endif #ifndef DK4TIME_H_INCLUDED #include "dk4time.h" #endif #ifndef DK4TIMEDK_H_INCLUDED #include "dk4timedk.h" #endif #ifndef DK4TIME08_H_INCLUDED #include "dk4time08.h" #endif int dk4clocktime_get(dk4_clock_time_t *dptr) { if (NULL != dptr) { #if DK4_ON_WINDOWS && (DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT) GetLocalTime(dptr); return 1; #else dk4time_get(dptr); return 1; #endif } else { return 0; } } int dk4clocktime_compare(const dk4_clock_time_t *l, const dk4_clock_time_t *r) { int back = 0; if (NULL != l) { if (NULL != r) { #if DK4_ON_WINDOWS && (DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT) if (l->wYear > r->wYear) { back = 1; } else { if (l->wYear < r->wYear) { back = -1; } } if (0 == back) { if (l->wMonth > r->wMonth) { back = 1; } else { if (l->wMonth < r->wMonth) { back = -1; } } } if (0 == back) { if (l->wDay > r->wDay) { back = 1; } else { if (l->wDay < r->wDay) { back = -1; } } } if (0 == back) { if (l->wHour > r->wHour) { back = 1; } else { if (l->wHour < r->wHour) { back = -1; } } } if (0 == back) { if (l->wMinute > r->wMinute) { back = 1; } else { if (l->wMinute < r->wMinute) { back = -1; } } } if (0 == back) { if (l->wSecond > r->wSecond) { back = 1; } else { if (l->wSecond < r->wSecond) { back = -1; } } } #else if (*l > *r) { back = 1; } else { if (*l < *r) { back = -1; } } #endif } else { back = 1; } } else { if (NULL != r) { back = -1; } } return back; } /** Convert timestamp to text ``yyyy-mm-dd hh:mm:ss''. @param dptr Result buffer address. @param dsz Result buffer size (number of dkChar). @param clt Timestamp to convert. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4clocktime_to_text( dkChar *dptr, size_t dsz, const dk4_clock_time_t *clt, dk4_er_t *erp ) { #if DK4_ON_WINDOWS && (DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT) back = dk4time_to_text( dptr, dsz, DK4_TIMEFORMAT_DATE_TIME, clt->wYear, clt->wMonth, clt->wDay, clt->wHour, clt->wMinute, clt->wSecond, erp ); #else #if DK4_CHAR_SIZE > 1 char buf[32]; int back = 0; if (0 != dk4time_as_text_c8(buf, sizeof(buf), clt, erp)) { back = dk4recode_char_to_dk(dptr, dsz, buf, erp); } return back; #else return (dk4time_as_text(dptr, dsz, clt, erp)); #endif #endif }