/* **********************************************************************
 * *                                                                    *
 * *          Routine to Test Time Manipulating Functions               *
 * *                                                                    *
 * **********************************************************************
 * File: /libs/user/test_time.c
 *
 *                        COPYRIGHT (c) 2006  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */
#include <locale.h>
#include <stdio.h>
#include <string.h>

#include "sigtypes.h"
#include "user_lib.h"

static void PrintAndAdd( struct ymds_time *pYmds_a );

/* ==========================================================================
 */
int main( int iargc, char **sargv )
{
  char sTimeBuf[TIMENAME_SIZE];
  struct full_time_spec Time;
  struct ymds_time Ymds;
  UINT2 iMills;

/* ------------------------------------------------------------ */
  if( !setlocale(LC_ALL, "") )
    {
      printf("Setlocale failed, using C locale.\n") ;
    }

  /* Print out information about the current time and zone */
  GetTimeFull( &Time, TIME_FLG_LOCAL );
  printf( "Current Time:%s\n", shhmmssmmm_ddmonyyyy( &Time.Ymds, sTimeBuf ) );
  printf( "TZ Name:%s, Minutes West:%d, DST:%d, LDST:%d, UTC:%d\n\n", 
	  Time.sRecordTZName, Time.iMinutesWest, DST_FROM_MILLS(Time.Ymds.imills),
	  LDST_FROM_MILLS(Time.Ymds.imills), UTC_FROM_MILLS(Time.Ymds.imills) );
  
  /* Loop through all possible time flag options */
  for (iMills=0; iMills<(YMDS_FLG_LDST<<1); iMills+=YMDS_FLG_DST)
    {
      /* Now do a test time addition overnight */
      memset( &Ymds, 0, sizeof(Ymds) );
      Ymds.iyear = 2005;
      Ymds.imon  = 1;
      Ymds.iday  = 25;
      Ymds.isec  = 23*3600 + 1800;  /* 23:30 */
      Ymds.imills = iMills;

      PrintAndAdd( &Ymds );
    }

  return(0) ;
}
/* =======================================================
 * Print out time, add one hour, then print out again.
 */
static void PrintAndAdd( struct ymds_time *pYmds_a )
{
  char sTimeBuf[TIMENAME_SIZE];
 
  printf( "Before: %s, DST:%d, LDST:%d, UTC:%d\n", 
	   shhmmssddmonyyyy_r( pYmds_a, sTimeBuf ), DST_FROM_MILLS(pYmds_a->imills),
	   LDST_FROM_MILLS(pYmds_a->imills), UTC_FROM_MILLS(pYmds_a->imills) );

  ymds_add_seconds( 3600, pYmds_a );
  
  printf( "After:  %s, DST:%d, LDST:%d, UTC:%d\n\n",
	   shhmmssddmonyyyy_r( pYmds_a, sTimeBuf ), DST_FROM_MILLS(pYmds_a->imills),
	   LDST_FROM_MILLS(pYmds_a->imills), UTC_FROM_MILLS(pYmds_a->imills) );

}
