Any projects which want to use Hush code from now on will need to be licensed as GPLv3 or we will send the lawyers: https://www.softwarefreedom.org/ Notably, Komodo (KMD) is licensed as GPLv2 and is no longer compatible to receive code changes, without causing legal issues. MIT projects, such as Zcash, also cannot pull in changes from the Hush Full Node without permission from The Hush Developers, which may in some circumstances grant an MIT license on a case-by-case basis.
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
|
// Distributed under the GPLv3 software license, see the accompanying
|
|
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
#include "config/bitcoin-config.h"
|
|
#endif
|
|
|
|
#include "utiltime.h"
|
|
|
|
#include <chrono>
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
#include <boost/thread.hpp>
|
|
|
|
using namespace std;
|
|
|
|
static int64_t nMockTime = 0; //! For unit testing
|
|
|
|
int64_t GetTime()
|
|
{
|
|
if (nMockTime) return nMockTime;
|
|
|
|
return time(NULL);
|
|
}
|
|
|
|
void SetMockTime(int64_t nMockTimeIn)
|
|
{
|
|
nMockTime = nMockTimeIn;
|
|
}
|
|
|
|
int64_t GetTimeMillis()
|
|
{
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
std::chrono::system_clock::now().time_since_epoch()).count();
|
|
}
|
|
|
|
int64_t GetTimeMicros()
|
|
{
|
|
return std::chrono::duration_cast<std::chrono::microseconds>(
|
|
std::chrono::system_clock::now().time_since_epoch()).count();
|
|
}
|
|
|
|
void MilliSleep(int64_t n)
|
|
{
|
|
boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
|
|
}
|
|
|
|
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
|
|
{
|
|
// std::locale takes ownership of the pointer
|
|
std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat));
|
|
std::stringstream ss;
|
|
ss.imbue(loc);
|
|
ss << boost::posix_time::from_time_t(nTime);
|
|
return ss.str();
|
|
}
|