Put json time as unix time.

This commit is contained in:
Arthur Britto
2012-10-15 14:22:07 -07:00
parent d98e415107
commit 42d7813046
3 changed files with 17 additions and 3 deletions

View File

@@ -901,7 +901,7 @@ Json::Value NetworkOPs::pubBootstrapAccountInfo(Ledger::ref lpAccepted, const Ne
jvObj["owner"] = getOwnerInfo(lpAccepted, naAccountID);
jvObj["ledger_closed_index"] = lpAccepted->getLedgerSeq();
jvObj["ledger_closed"] = lpAccepted->getHash().ToString();
jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC());
jvObj["ledger_closed_time"] = Json::Value::UInt(utFromSeconds(lpAccepted->getCloseTimeNC()));
return jvObj;
}
@@ -939,7 +939,7 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted)
jvObj["type"] = "ledgerClosed";
jvObj["ledger_closed_index"] = lpAccepted->getLedgerSeq();
jvObj["ledger_closed"] = lpAccepted->getHash().ToString();
jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC());
jvObj["ledger_closed_time"] = Json::Value::UInt(utFromSeconds(lpAccepted->getCloseTimeNC()));
BOOST_FOREACH(InfoSub* ispListener, mSubLedger)
{
@@ -964,7 +964,7 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted)
jvObj["type"] = "ledgerClosedAccounts";
jvObj["ledger_closed_index"] = lpAccepted->getLedgerSeq();
jvObj["ledger_closed"] = lpAccepted->getHash().ToString();
jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC());
jvObj["ledger_closed_time"] = Json::Value::UInt(utFromSeconds(lpAccepted->getCloseTimeNC()));
jvObj["accounts"] = jvAccounts;
BOOST_FOREACH(InfoSub* ispListener, mSubLedgerAccounts)

View File

@@ -22,6 +22,7 @@ int iToSeconds(boost::posix_time::ptime ptWhen)
: (ptWhen-ptEpoch()).total_seconds();
}
// Convert our time in seconds to a ptime.
boost::posix_time::ptime ptFromSeconds(int iSeconds)
{
return iSeconds < 0
@@ -29,6 +30,18 @@ boost::posix_time::ptime ptFromSeconds(int iSeconds)
: ptEpoch() + boost::posix_time::seconds(iSeconds);
}
// Convert from our time to UNIX time in seconds.
uint64_t utFromSeconds(int iSeconds)
{
boost::posix_time::time_duration tdDelta =
boost::posix_time::ptime(boost::gregorian::date(2000, boost::gregorian::Jan, 1))
-boost::posix_time::ptime(boost::gregorian::date(1970, boost::gregorian::Jan, 1))
+boost::posix_time::seconds(iSeconds)
;
return tdDelta.total_seconds();
}
//
// Hex suport
//

View File

@@ -90,6 +90,7 @@ extern uint32_t be32toh(uint32_t value);
boost::posix_time::ptime ptEpoch();
int iToSeconds(boost::posix_time::ptime ptWhen);
boost::posix_time::ptime ptFromSeconds(int iSeconds);
uint64_t utFromSeconds(int iSeconds);
/*
void intIPtoStr(int ip,std::string& retStr);