ROOT logo
// $Id: GTime.h 2800 2012-06-29 06:34:53Z matevz $

// Copyright (C) 1999-2008, Matevz Tadel. All rights reserved.
// This file is part of GLED, released under GNU General Public License version 2.
// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.

#ifndef GledCore_GTime_H
#define GledCore_GTime_H

#include <Rtypes.h>
#include <TString.h>

class TBuffer;

class GTime
{
  friend class Gled;

public:
  enum Init_e { I_Zero, I_Now, I_Never };

protected:
  Long64_t	mSec;	// X{GS}
  Long64_t	mNSec;	// X{GS}

  void canonize();

  static GTime    sApproximateTime;
  static Long64_t UpdateApproximateTime(const GTime& now);

public:
  GTime() : mSec(0), mNSec(0) {}
  explicit GTime(Init_e i);
  explicit GTime(Double_t s) { *this = s; }
  explicit GTime(Long64_t s, Long64_t ns) : mSec(s), mNSec(ns) { canonize(); }
  GTime(const GTime& t) : mSec(t.mSec), mNSec(t.mNSec) {}

  ~GTime() {}

  static GTime Now()   { return GTime(I_Now);   }
  static GTime Never() { return GTime(I_Never); }
  static GTime MiliSec(Long64_t ms) { return GTime(0, 1000000 * ms); }

  void   SetNow();
  GTime  TimeUntilNow();

  void   SetZero()         { mSec = mNSec = 0; }
  Bool_t IsZero()    const { return mSec == 0 && mNSec == 0; }
  Bool_t IsNonZero() const { return mSec != 0 || mNSec != 0; }

  void   SetNever();
  Bool_t IsNever() const;

  GTime& operator=(Double_t sec);

  GTime& operator+=(const GTime& t);
  GTime& operator-=(const GTime& t);

  GTime& operator+=(Double_t sec);
  GTime& operator-=(Double_t sec);

  GTime  operator+(const GTime& t) const;
  GTime  operator-(const GTime& t) const;

  bool   operator<(const GTime& t) const;
  bool   operator>(const GTime& t) const;
  bool   operator<=(const GTime& t) const;
  bool   operator>=(const GTime& t) const;
  bool   operator==(const GTime& t) const;

  Double_t ToDouble()  const { return mSec + 1e-9  * mNSec; }
  Float_t  ToFloat()   const { return mSec + 1e-9f * mNSec; }
  Long64_t ToMiliSec() const { return mSec*1000 + mNSec/1000000; }
  Long64_t ToMiliSec(Long64_t max_seconds) const
  { return mSec >= max_seconds ? max_seconds*1000 : mSec*1000 + mNSec/1000000; }

  TString  ToAscUTC  (Bool_t show_tz=true) const;
  TString  ToAscLocal(Bool_t show_tz=true) const;
  TString  ToDateTimeUTC  (Bool_t show_tz=true) const;
  TString  ToDateTimeLocal(Bool_t show_tz=true) const;
  TString  ToCompactDateTimeUTC  () const;
  TString  ToCompactDateTimeLocal() const;
  TString  ToDateUTC  () const;
  TString  ToDateLocal() const;
  TString  ToWebTimeGMT  (Bool_t show_tz=true) const;
  TString  ToWebTimeLocal(Bool_t show_tz=true) const;
  TString  ToHourMinSec(Bool_t force_non_negative=false) const;

  GTime    TimeOfTheDayUTC() const;
  GTime    TimeOfTheDayLocal() const;

  void     Sleep();

  static Long64_t SleepMiliSec(UInt_t ms,
			       Bool_t break_on_signal=true,
			       Bool_t warn_on_signal=true);

  static const GTime& ApproximateTime();

  void  NetStreamer(TBuffer& b);
  Int_t NetBufferSize() const { return 2 * sizeof(Long64_t); }

#include "GTime.h7"
  ClassDefNV(GTime, 1);
}; // endclass GTime

#endif
 GTime.h:1
 GTime.h:2
 GTime.h:3
 GTime.h:4
 GTime.h:5
 GTime.h:6
 GTime.h:7
 GTime.h:8
 GTime.h:9
 GTime.h:10
 GTime.h:11
 GTime.h:12
 GTime.h:13
 GTime.h:14
 GTime.h:15
 GTime.h:16
 GTime.h:17
 GTime.h:18
 GTime.h:19
 GTime.h:20
 GTime.h:21
 GTime.h:22
 GTime.h:23
 GTime.h:24
 GTime.h:25
 GTime.h:26
 GTime.h:27
 GTime.h:28
 GTime.h:29
 GTime.h:30
 GTime.h:31
 GTime.h:32
 GTime.h:33
 GTime.h:34
 GTime.h:35
 GTime.h:36
 GTime.h:37
 GTime.h:38
 GTime.h:39
 GTime.h:40
 GTime.h:41
 GTime.h:42
 GTime.h:43
 GTime.h:44
 GTime.h:45
 GTime.h:46
 GTime.h:47
 GTime.h:48
 GTime.h:49
 GTime.h:50
 GTime.h:51
 GTime.h:52
 GTime.h:53
 GTime.h:54
 GTime.h:55
 GTime.h:56
 GTime.h:57
 GTime.h:58
 GTime.h:59
 GTime.h:60
 GTime.h:61
 GTime.h:62
 GTime.h:63
 GTime.h:64
 GTime.h:65
 GTime.h:66
 GTime.h:67
 GTime.h:68
 GTime.h:69
 GTime.h:70
 GTime.h:71
 GTime.h:72
 GTime.h:73
 GTime.h:74
 GTime.h:75
 GTime.h:76
 GTime.h:77
 GTime.h:78
 GTime.h:79
 GTime.h:80
 GTime.h:81
 GTime.h:82
 GTime.h:83
 GTime.h:84
 GTime.h:85
 GTime.h:86
 GTime.h:87
 GTime.h:88
 GTime.h:89
 GTime.h:90
 GTime.h:91
 GTime.h:92
 GTime.h:93
 GTime.h:94
 GTime.h:95
 GTime.h:96
 GTime.h:97
 GTime.h:98
 GTime.h:99
 GTime.h:100
 GTime.h:101
 GTime.h:102
 GTime.h:103
 GTime.h:104
 GTime.h:105
 GTime.h:106
 GTime.h:107