// $Id: xxl_time.cc,v 1.2 1996/12/11 21:39:52 aml Exp $ 

#include "xxl_funcs.hh"
#include "sheet.hh"

int month_function(double fv) {

  time_t  tt;
  struct tm *tm;
  int res;

  fv = fv-DAYS_BETWEEN_1970_1900;
  if (fv > 0) {
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      res = tm->tm_mon+1;
  } else
      res = 0;
  return(res);
}

int day_function(double fv) {
  time_t  tt;
  struct tm *tm;
  int res;

  if (fv > 0) {
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      res = tm->tm_mday;
  }
  else 
      res = 0;
  
  return(res);
}

int hour_function(double fv) {
  time_t  tt;
  struct tm *tm;
  int res;

  if (fv > 0) {
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      res = tm->tm_hour;
  } else 
      res = 0;
  return(res);
}

int minute_function(double fv) {
  time_t  tt;
  struct tm *tm;
  int res;

  if (fv > 0) {
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      res = tm->tm_min;
  } else 
      res = 0;

  return(res);
}

int second_function(double fv) {
  time_t  tt;
  struct tm *tm;
  int res;

  if (fv > 0) {
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      res = tm->tm_sec;
  } else
      res = 0;
  return(res);
}


// $Log: xxl_time.cc,v $
// Revision 1.2  1996/12/11  21:39:52  aml
// Sumif implemented.
// Diverse time functions implemented.
// Fixed needtoscroll2 to avoid out of control scroll.
//
// Revision 1.1  1996/11/28 16:30:23  aml
// Initial revision
//
