home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * ut_date.c - utility date functions.
- *
- * Purpose: This file contains functions to operate on the date and time.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <string.h>
- #include "blackstr.h"
- #include "ut_head.h"
-
-
- /********
- *
- * ut_gtod() - gets time and date
- *
- **/
-
- void ut_gtod(void)
- {
- ut_gdate();
- sy_gtime();
- }
-
-
- /********
- *
- * ut_gdate() - get date
- *
- **/
-
- void ut_gdate(void)
- {
- sy_gdate(); /* use library function */
- leapf_ = (year_%4)? 0 : 1;
- }
-
-
- /********
- *
- * ut_gtime() - get time
- *
- **/
-
- void ut_gtime(void)
- {
- sy_gtime(); /* use pclib function */
- }
-
-
- /********
- *
- * ut_datel() - get long date
- *
- **/
-
- long ut_datel(void)
- {
- ut_gdate(); /* get date */
- return(((year_-1900)*10000L)+(month_*100L)+(long)day_);
- }
-
-
- /********
- *
- * ut_timel() - get long time
- *
- **/
-
- long ut_timel(void)
- {
- sy_gtime();
- return((hour_*10000L) + (minute_*100L) + (long)sec_);
- }
-
-
- /********
- *
- * ut_dates(sdate) - get date to structure
- *
- **/
-
- void ut_dates(struct DATE *sdate)
- {
- ut_gdate();
- sdate->yr = year_;
- sdate->mo = month_;
- sdate->dy = day_;
- }
-
-
- /********
- *
- * ut_times(stime) - get time to structure
- *
- **/
-
- void ut_times(struct TIME *stime)
- {
- sy_gtime();
- stime->hr = hour_;
- stime->mn = minute_;
- stime->sec = sec_;
- stime->hsec = hsec_;
- }
-
-
- /********
- *
- * ut_sdatestr(str,sdate) - get structured date to string
- *
- **/
-
- void ut_sdatestr(char *str, struct DATE *sdate)
- {
- char buff[30];
- int year;
-
- if(dateoptf_&DTNDF) {
- sprintf(str,"%s, ",ut_daystr(ut_sday(sdate)));/*day */
- }else
- strcpy(str,"");
-
- if(dateoptf_&DTNMF) {
- sprintf(buff,"%s %d, ",ut_mostr(sdate->mo),sdate->dy);
- strcat(str,buff);
- }else {
- sprintf(buff,"%2d/%d/",sdate->mo,sdate->dy);
- strcat(str,buff);
- }
-
- year = sdate->yr;
- if(dateoptf_&DYR2F) {
- year %= 100; /* 2 digit year */
- sprintf(buff,"%2d",year); /* add year */
- strcat(str,buff);
- }else { /* 4 digit year */
- sprintf(buff,"%4d",year); /* add year */
- strcat(str,buff);
- }
- }
-
-
- /********
- *
- * ut_stimestr(str,stime) - get struct TIME to string in hh:mm am format
- *
- **/
-
- void ut_stimestr(char *str, struct TIME *stime)
- {
- char *ampm;
- int hour;
-
- hour = stime->hr;
- ampm = "";
- if(!(timeoptf_&T24HF)) { /* 24 hr format */
- if(hour>11)
- ampm = "pm";
- else
- ampm = "am";
- if(!hour)
- hour= 12;
- else
- if(hour>12)
- hour %= 12;
- }
- if(!(timeoptf_&TSECF))
- sprintf(str,"%2d:%02d",hour,stime->mn);
- else
- sprintf(str,"%2d:%02d:%02d.%02d",hour,stime->mn,
- stime->sec,stime->hsec);
- strcat(str,ampm);
- }
-
-
- /********
- *
- * ut_ldates(sdate,ldate) - convert long date to structure
- *
- **/
-
- void ut_ldates(struct DATE *sdate, long int ldate)
- {
- sdate->yr = ldate/10000L; /* year */
- sdate->mo = (ldate -(sdate->yr*10000L))/100; /* month */
- sdate->dy = (ldate-(sdate->yr * 10000L))%100; /* day */
- if(!(dateoptf_&DYR2F))
- sdate->yr += 1900;
- }
-
-
- /********
- *
- * ut_ldatestr(str,ldate) - convert long date to string
- *
- **/
-
- void ut_ldatestr(char *str, long ldate)
- {
- struct DATE sdate;
-
- ut_ldates(&sdate,ldate); /* convert to structure */
- ut_sdatestr(str,&sdate);
- }
-
-
- /********
- *
- * ut_ltimestr(str,ltime) - convert long time to string
- *
- **/
-
- void ut_ltimestr(char *str, long ltime)
- {
- struct TIME stime;
-
- ut_ltimes(&stime,ltime);
- ut_stimestr(str,&stime);
- }
-
-
- /********
- *
- * ut_ltimes(stime,ltime) - convert long time to structure
- *
- **/
-
- void ut_ltimes(struct TIME *stime, long ltime)
- {
- stime->hr = ltime/10000L;
- stime->mn = (ltime-stime->hr*10000L)/100L;
- stime->sec = ltime%100;
- stime->hsec = 0; /* no room for hsecs */
- }
-
-
- /********
- *
- * ut_hmtimestr(str,hr,mn) - convert hours,minutes to string
- *
- **/
-
- void ut_hmtimestr(char *str, int hr, int mn) /* must be 8 characters */
- {
- struct TIME stime;
-
- stime.hr = hr;
- stime.mn = mn;
- stime.sec=stime.hsec=0;
- ut_stimestr(str,&stime);
- }
-
-
- /********
- *
- * ut_pause(time) - pause until time 1/100's secs passed
- *
- **/
-
- void ut_pause(int time)
- {
- struct TIME stime;
- int t1,t2;
-
- ut_times(&stime); /* get current time*/
- t1 = t2 = 100*stime.sec+stime.hsec;
- while(t2-t1<time) {
- ut_times(&stime);
- t2 = 100*stime.sec+stime.hsec;
- if(t2<t1) t2 += 6000; /* add a minute */
- }
- }
-