LCOV - code coverage report
Current view: top level - libs/datetime - time.hpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 4 4 100.0 %
Date: 2018-12-05 17:11:35 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #ifndef IROHA_TIME_H
       7             : #define IROHA_TIME_H
       8             : 
       9             : #include <chrono>
      10             : 
      11             : namespace iroha {
      12             : 
      13             :   // timestamps
      14             :   using ts64_t = uint64_t;
      15             :   using ts32_t = uint32_t;
      16             : 
      17             :   namespace time {
      18             : 
      19             :     /**
      20             :      * Returns current UNIX timestamp.
      21             :      * Represents number of milliseconds since epoch.
      22             :      */
      23             :     inline auto now() {
      24        7985 :       return std::chrono::system_clock::now().time_since_epoch()
      25        7985 :           / std::chrono::milliseconds(1);
      26             :     }
      27             : 
      28             :     /**
      29             :      * Return UNIX timestamp with given offset.
      30             :      * Represents number of milliseconds since epoch.
      31             :      */
      32             :     template <typename T>
      33             :     inline auto now(const T &offset) {
      34          15 :       return (std::chrono::system_clock::now().time_since_epoch() + offset)
      35          15 :           / std::chrono::milliseconds(1);
      36             :     }
      37             : 
      38             :     using time_t = decltype(iroha::time::now());
      39             :   }  // namespace time
      40             : }  // namespace iroha
      41             : 
      42             : #endif  // IROHA_TIME_H

Generated by: LCOV version 1.13