/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__NTIME__
#define	__NTIME__


		#include "nstring/nstring.h"


namespace GS {

/*!
	@short	Time class.
	@author Emmanuel Julien (ejulien@gsworks.fr)
*/
class	Time
{
		int			sec, nsec;	// second, nanosecond (10^9 -> 1 billionth second) (63+ years loop)

public:

static	Time		Inf;

		void		operator += (const Time &);
		void		operator -= (const Time &);
		Time		operator + (const Time &) const;
		Time		operator - (const Time &) const;

template <class T> void operator *= (T k) { sec = int(T(sec) * k); nsec = int(T(nsec) * k); Normalize(); }
template <class T> void operator /= (T k) { sec = int(T(sec) / k); nsec = int(T(nsec) / k); Normalize(); }
template <class T> Time operator * (T k) const { return Time(int(T(sec) * k), int(T(nsec) * k)); }
template <class T> Time operator / (T k) const { return Time(int(T(sec) / k), int(T(nsec) / k)); }

		bool		operator > (const Time &) const;
		bool		operator < (const Time &) const;
		bool		operator >= (const Time &) const;
		bool		operator <= (const Time &) const;
		bool		operator == (const Time &) const;
		bool		operator != (const Time &) const;

		Time		Abs() const;

		int			getSec() const { return sec; }
		int			getNanoSec() const { return nsec; }

		float		toDay() const;
		float		toHour() const;
		float		toMin() const;
		float		toSec() const;
		float		toMs() const;
		float		toNs() const;
		
		String		toString() const;
		
		void		setSec(float);
		void		setSec(int);
		void		setMs(int);
		void		setNs(int);

static	Time		fromSec(float);
static	Time		fromSec(int);
static	Time		fromMs(int);
static	Time		fromNs(int);

		void		Normalize();
		Time		Normalized() const;

		Time(const int sec, const int nsec);

		explicit Time(const int sec = 0);
		explicit Time(const float sec);
};

} // GS


#endif	// __NTIME__
