Index: /trunk/SophyaLib/BaseTools/timestamp.cc
===================================================================
--- /trunk/SophyaLib/BaseTools/timestamp.cc	(revision 2654)
+++ /trunk/SophyaLib/BaseTools/timestamp.cc	(revision 2654)
@@ -0,0 +1,225 @@
+#include "sopnamsp.h"
+#include "machdefs.h"
+#include <stdio.h>
+#include <time.h>
+#include <ctype.h>
+#include <math.h>
+#include "timestamp.h"
+#include "pexceptions.h"
+#include <iostream>
+
+//-------------------------------------------------------------------------
+//--------------------------  Classe TimeStamp   --------------------------
+//-------------------------------------------------------------------------
+enum Jour {jour_Lundi=0, jour_Mardi, jour_Mercredi, jour_Jeudi, jour_Vendredi, jour_Samedi, jour_Dimanche};
+enum Mois {mois_Janvier=1, mois_Fevrier, mois_Mars, mois_Avril, mois_Mai, mois_Juin, mois_Juillet,
+		   mois_Aout, mois_Septembre, mois_Octobre, mois_Novembre, mois_Decembre};
+
+  /*
+  //! Day of the week enum
+  enum WeekDay {day_Monday=0, day_Tuesday, day_Wednesday, day_Thursday, day_Friday, day_Saturday, day_Sunday};
+  */
+ 
+TimeStamp::TimeStamp()
+{
+  mSeconds = 0.;
+  mDays = 0;
+  SetNow();
+}
+
+TimeStamp::TimeStamp(TimeStamp const & ts)
+{
+  Set(ts);
+  mSeconds = ts.mSeconds;
+  mDays = ts.mDays;
+}
+
+TimeStamp::TimeStamp(int year, int month, int day, int hour, int min, double sec)
+{
+  SetDate(year, month, day);
+  SetHour(hour, min, sec);
+}
+
+
+TimeStamp::TimeStamp(double days)
+{
+  Set(days);
+}
+
+TimeStamp::TimeStamp(string& date, string& hour)
+{
+  SetDate(date);
+  SetHour(hour);
+}
+
+TimeStamp::TimeStamp(const char* date, const char* hour)
+{
+  SetDate(date);
+  SetHour(hour);
+}
+
+
+void TimeStamp::Set(TimeStamp const & ts)
+{
+  mSeconds = ts.mSeconds;
+  mDays = ts.mDays;
+}
+
+void TimeStamp::Set(double days)
+{
+  if (days < 0.) {
+    mDays = days;
+    mSeconds = (days-mDays)*86400.;
+  }
+  else {
+    mDays = trunc(days)-1;
+    mSeconds = (days-mDays)*86400.;
+  }
+}
+
+void TimeStamp::SetNow()
+{
+  time_t t = time(NULL);
+  struct tm* TM = gmtime(&t);
+
+  int JJ,MM,AA;
+  int hh,mm;
+  double ss; 
+  
+  AA = TM->tm_year + 1900;
+  MM = TM->tm_mon+1;
+  JJ = TM->tm_mday;
+  hh = TM->tm_hour;
+  mm = TM->tm_min;
+  ss = TM->tm_sec;
+  SetDate(AA,MM,JJ);
+  SetHour(hh,mm,ss);
+}
+
+void TimeStamp::SetDate(int year, int month, int day)
+{
+  mDays = ConvertToDays(year, month, day);
+}
+
+void TimeStamp::SetDate(const char* date)
+{
+  int day,month,year;
+  sscanf(date,"%d/%d/%d", &day, &month, &year);
+  mDays = ConvertToDays(year, month, day);
+}
+
+void TimeStamp::SetHour(int hour, int min, double sec)
+{
+  mSeconds = hour*3600.+min*60+sec;
+}
+
+void TimeStamp::SetHour(const char* shour)
+{
+  int hour, min;
+  double sec;
+  sscanf(shour,"%d:%d:%lf",&hour, &min, &sec);
+  mSeconds = hour*3600.+min*60+sec;
+
+}
+
+void TimeStamp::GetDate(int& year, int& month, int& day) const
+{
+  int_8 jours = mDays;
+  // Recherche de l'annee
+  if (jours < 0) {
+    year = 1901;
+    while(jours < 0)  { 
+      year--;
+      jours += YearDays(year); 
+    }
+  }
+  else {
+    year = 1901;
+    while(jours > YearDays(year))  { 
+      jours -= YearDays(year); 
+      year++;
+    }
+  }
+  // Recherche du mois
+  month = 1;
+  while(jours > MonthDays(year, month) )  { 
+    jours -= MonthDays(year, month);
+    month++;
+  }
+  day = jours;
+}
+
+void TimeStamp::GetHour(int& hour, int& min, double& sec) const
+{
+  double seconds = mSeconds;
+  hour = trunc(seconds/3600.);
+  seconds -= hour*3600;
+  min = trunc(seconds/60.);
+  sec = seconds-min*60;
+}
+double TimeStamp::ToDays() const
+{
+  return((double)mDays + mSeconds/86400.);
+}
+
+string TimeStamp::ToString() const
+{
+  char buff[128];
+  int aa, mm, jj;
+  int hh, min;
+  double sec;
+  GetDate(aa, mm, jj);
+  GetHour(hh, min, sec);
+  sprintf(buff,"%02d/%02d/%02d %02d:%02d:%02.1f GMT", jj,mm,aa,hh,min,sec);
+  return buff;
+}
+
+void TimeStamp::Print(ostream& os)  const
+{
+  os << " " << ToString() << " "; 
+}
+
+int TimeStamp::MonthDays(int annee, int mois) 
+{
+  if (mois<1 || mois>12) throw ParmError("TimeStamp::MonthDays month out of range");
+  
+  switch(mois) {
+    case mois_Janvier: 
+    case mois_Mars:
+    case mois_Mai:
+    case mois_Juillet:
+    case mois_Aout:
+    case mois_Octobre:
+    case mois_Decembre:
+      return 31;
+    case mois_Avril:
+    case mois_Juin:
+    case mois_Septembre:
+    case mois_Novembre:
+      return 30;
+    case mois_Fevrier:
+     return (((annee%4 == 0) && (annee%100 != 0)) || (annee%400 == 0)) ? 29 : 28;
+  }
+  return -1;
+}
+
+int TimeStamp::YearDays(int annee)
+//	Retourne le nombre de jours dans l'année
+{
+  return (((annee%4 == 0) && (annee%100 != 0)) || (annee%400 == 0)) ? 366 : 365;
+}
+
+int_8 TimeStamp::ConvertToDays(int AA, int MM, int JJ)
+{
+  int_8 t = 0;
+  //   if (!UndetDate()) {
+  int nban = AA-1901;
+  if (nban >= 0)  
+    t = nban*365 + (nban/4) - (nban/100) + ((nban+300)/400);
+  else 
+    t = nban*365 + (nban/4) - (nban/100) + ((nban-100)/400);
+  for (int i=1; i<MM; i++)  t += TimeStamp::MonthDays(AA, i);
+  t += JJ;
+  // }
+  return t;
+}
Index: /trunk/SophyaLib/BaseTools/timestamp.h
===================================================================
--- /trunk/SophyaLib/BaseTools/timestamp.h	(revision 2654)
+++ /trunk/SophyaLib/BaseTools/timestamp.h	(revision 2654)
@@ -0,0 +1,103 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+#ifndef TIMESTAMP_H_SEEN
+#define TIMESTAMP_H_SEEN
+
+// Classe TimeStamp (Date+heure)
+//
+// R. Ansari      UPS+LAL IN2P3/CNRS  2005
+// Code recupere en partie ds dates.h dates.cc (classe Date) / E. Aubourg 1995-2000
+
+
+#include "machdefs.h"
+#include <string> 
+#include <iostream> 
+
+namespace SOPHYA {
+  
+//! Class representing date and time
+class TimeStamp {
+public:
+  /*  Pour utilisation ulterieure
+  //! GMT / local time enum 
+  enum {kGMTTime=0, kLocalTime=1};
+  */
+  //! Month name enum
+  enum Month {month_January=1, month_February, month_March, month_April, month_May, month_June, month_July,
+             month_August, month_September, month_October, month_November, month_December};  
+
+  //! Default Constructor : current date and time (GMT)
+  TimeStamp();
+  TimeStamp(TimeStamp const & ts);
+  //! Constructor with specification of number of days since 0 Jan 1901 0h TU 
+  TimeStamp(double days);
+  //! Constructor with specification of day,month,year,hour,minutes,seconds 
+  TimeStamp(int year, int month, int day, int hour, int min, double sec);
+  //! Constructor with specification of date & time in the format YYYY/MM/DD hh:mm:ss
+  TimeStamp(string& date, string& hour);
+  TimeStamp(const char* date, const char* hour);
+
+  //! Set the value of the time stamp copying from "ts"
+  void Set(TimeStamp const & ts);
+  //! Sets the value of the time stamp from the number of days since 0 Jan 1901 0h TU 
+  void Set(double days);
+  //! initialize with current date and time (GMT)
+  void SetNow();
+
+  //! The equal (set) operator 
+  inline TimeStamp& operator= (TimeStamp const & ts) 
+    { Set(ts); return(*this); }
+
+  //! Sets the value of the date (days) 
+  void SetDate(int year, int month, int day);
+  //! Sets the value of the date (format: DD/MM/YYYY) 
+  void SetDate(const char* date); 
+  //! Sets the value of the date (format: DD/MM/YYYY) 
+  inline void SetDate(string const& date) { SetDate(date.c_str()); }
+
+  //! Sets the value of the time of day (hours) 
+  void SetHour(int hour, int min, double sec);
+  //! Sets the value of the time of day (format: hh:mm:ss[.ss]) 
+  void SetHour(const char* hour); 
+  //! Sets the value of the time of day (format: hh:mm:ss[.ss]) 
+  inline void SetHour(string const& hour) { SetHour(hour.c_str()); }
+
+  //! Return the date (Year, Month, Day)
+  void GetDate(int& year, int& month, int& day) const;
+  //! Return the time of the day
+  void GetHour(int& hour, int& min, double& sec) const;
+
+  //! Return the value of the TimeStamp as days.fraction_days since 0 Jan 1901
+  double ToDays() const;
+  //! Conversion operator to double
+  inline operator double() const { return ToDays(); }
+
+  //! Return the timestamp in string format 
+  string ToString() const;
+  
+  /*! Prints the date/time in string format on \b cout */
+  inline  void    Print() const  { Print(cout); }  
+  /*! Prints the date/time in string format on stream \b os */
+  virtual void    Print(ostream& os)  const;
+
+  //! 
+  //! Number of days in a given month  
+  static int   MonthDays(int year, int month);
+  //! Number of days in a given year
+  static int YearDays(int annee);
+  //! Number of  days since 0 janvier 1901 0h TU
+  static int_8 ConvertToDays(int year, int month, int day);
+  
+
+protected:
+  r_8 mSeconds;     // Number of seconds since 00:00:00 
+  int_8 mDays;      // Number of days since 0 Jan 1901
+};
+
+/*! operator << overloading - Prints date/time in string format on \b os*/
+inline ostream& operator << (ostream& s, TimeStamp const & ts)
+  {  ts.Print(s);  return(s);  }
+
+} // namespace SOPHYA
+
+#endif
