Something went wrong. Try again.
Cider Isn't Darwin Emulation, Really
Something went wrong. Try again.
2.2 kB · 107 lines
C++
at android
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108/*This file is part of Darling.
Copyright (C) 2012-2016 Lubos Dolezel
Darling is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.
Darling is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.
You should have received a copy of the GNU General Public Licensealong with Darling. If not, see <http://www.gnu.org/licenses/>.*/
#include "DateTimeUtils.h"#include <climits>#include <ctime>
UTCDateTime Darling::time_tToUTC(time_t t){ UTCDateTime rv; uint64_t time = t + UNIX_OFFSET;
rv.fraction = 0; rv.lowSeconds = time & 0xffffffff; rv.highSeconds = time >> 32;
return rv;}
OSErr UCConvertUTCDateTimeToCFAbsoluteTime(const UTCDateTime* in, CFAbsoluteTime* out){ uint64_t seconds = in->lowSeconds; seconds |= uint64_t(in->highSeconds) << 32; *out = seconds - CF_OFFSET; *out += (1.0/65535) * in->fraction; return noErr;}
OSErr UCConvertSecondsToCFAbsoluteTime(uint32_t seconds, CFAbsoluteTime* out){ *out = seconds; return noErr;}
OSErr UCConvertLongDateTimeToCFAbsoluteTime(int64_t seconds, CFAbsoluteTime* out){ *out = seconds; return noErr;}
OSErr UCConvertCFAbsoluteTimeToUTCDateTime(CFAbsoluteTime in, UTCDateTime* out){ in += CF_OFFSET;
if (in > 2.0e48) return paramErr;
uint64_t seconds = uint64_t(in);
out->lowSeconds = seconds & 0xffffffff; out->highSeconds = seconds >> 32; out->fraction = uint16_t((in-seconds) * 65535);
return noErr;}
OSErr UCConvertCFAbsoluteTimeToSeconds(CFAbsoluteTime in, uint32_t* out){ if (in <= UINT_MAX) { *out = uint32_t(in); return noErr; } else { *out = 0; return paramErr; }}
OSErr UCConvertCFAbsoluteTimeToLongDateTime(CFAbsoluteTime in, int64_t* out){ if (in <= LLONG_MAX) { *out = int64_t(in); return noErr; } else { *out = 0; return paramErr; }}
void GetDateTime(unsigned long* secs){ time_t t; time(&t); *secs = t + 2082844800l;}