home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * ut_day.c - day of the week functions.
- *
- * Purpose: This file contains funcitons to operate on the date and time.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include "blackstr.h"
- #include "ut_head.h"
-
-
- /********
- *
- * ut_today() - get today's day of week integer
- *
- **/
-
- int ut_today(void)
- {
- return(ut_sday(&today_));
- }
-
-
- /********
- *
- * ut_sday(sdate) - get day of week structure
- *
- **/
-
- int ut_sday(struct DATE *sdate)
- {
- int dof,year;
-
- /* First do years offset (only from 1900) */
-
- year = sdate->yr;
- while(year>150) year -= 1900; /* only works from 1900 */
- dof = 1+year; /* for each year since 1900 */
- dof += (year-1)/4; /* for leap years that passed */
-
- /* Now calculate days of this year offset */
-
- dof += (ut_sjday(sdate)-1); /* just use Julian day offset */
- return(dof%7); /* mod 7 for day of week offset */
- }
-
-
- /********
- *
- * ut_ldaystr(ldate) - return day of week string from long date
- *
- **/
-
- char *ut_ldaystr(long ldate)
- {
- struct DATE sdate;
-
- ut_ldates(&sdate,ldate); /* convert to structure */
- return(ut_daystr(sdate.dy));
- }
-
-
- /********
- *
- * ut_sjday(sdate) - structure date to julian day of year
- *
- **/
-
- int ut_sjday(struct DATE *sdate)
- {
- int i,dy;
-
- dy = 0;
- for(i=0; i<sdate->mo; ++i)
- dy += mo_days_[i]; /* days in months */
- if(!(sdate->yr%4)&&(sdate->mo>2))
- ++dy; /* add for leap year */
- return(dy + (sdate->dy));
- }
-
-
- /********
- *
- * ut_daystr(day) - get pointer to day string
- *
- **/
-
- char *ut_daystr(int day)
- {
- extern char *dy_3names_[],*dy_names_[];
-
- if(dateoptf_&DDY3F)
- return(dy_3names_[day]);
- return(dy_names_[day]);
- }
-
-
- /********
- *
- * ut_mostr(mo) - get pointer to month name string
- *
- **/
-
- char *ut_mostr(int mo)
- {
- extern char *mo_3names_[],*mo_names_[];
-
- if(dateoptf_&DMO3F)
- return(mo_3names_[mo-1]);
- return(mo_names_[mo-1]);
- }
-
-
- /********
- *
- * ut_thismostr() - get this month to string
- *
- **/
-
- char *ut_thismo(void)
- {
- ut_gdate(); /* update it */
- return(ut_mostr(month_));
- }
-
-
- /********
- *
- * ut_todaystr() - return pointer to today's day of week
- *
- **/
-
- char *ut_todaystr(void)
- {
- return(ut_daystr(ut_today()));
- }
-
-