home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / UT_DAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  2.4 KB  |  142 lines

  1. /*********************
  2.  *
  3.  *  ut_day.c - day of the week functions.
  4.  *
  5.  *  Purpose: This file contains funcitons to operate on the date and time.
  6.  *
  7.  *  Blackstar C Function Library
  8.  *  (c) Copyright 1985,1989 Sterling Castle Software
  9.  *
  10.  *******/
  11.  
  12. #include "blackstr.h"
  13. #include "ut_head.h"
  14.  
  15.  
  16. /********
  17.  *
  18.  *   ut_today() - get today's day of week integer
  19.  *
  20.  **/
  21.  
  22. int ut_today(void)
  23. {
  24.     return(ut_sday(&today_));
  25. }
  26.  
  27.  
  28. /********
  29.  *
  30.  *   ut_sday(sdate) - get day of week structure
  31.  *
  32.  **/
  33.  
  34. int ut_sday(struct DATE *sdate)
  35. {
  36.     int dof,year;
  37.  
  38.     /* First do years offset (only from 1900) */
  39.  
  40.     year = sdate->yr;
  41.     while(year>150) year -= 1900;   /* only works from 1900  */
  42.     dof = 1+year;               /* for each year since 1900  */
  43.     dof += (year-1)/4;         /* for leap years that passed */
  44.  
  45.     /* Now calculate days of this year offset */
  46.  
  47.     dof += (ut_sjday(sdate)-1);     /* just use Julian day offset   */
  48.     return(dof%7);                  /* mod 7 for day of week offset */
  49. }
  50.  
  51.  
  52. /********
  53.  *
  54.  *   ut_ldaystr(ldate) - return day of week string from long date
  55.  *
  56.  **/
  57.  
  58. char *ut_ldaystr(long ldate)
  59. {
  60.     struct DATE sdate;
  61.  
  62.     ut_ldates(&sdate,ldate);        /* convert to structure */
  63.     return(ut_daystr(sdate.dy));
  64. }
  65.  
  66.  
  67. /********
  68.  *
  69.  *   ut_sjday(sdate) - structure date to julian day of year
  70.  *
  71.  **/
  72.  
  73. int ut_sjday(struct DATE *sdate)
  74. {
  75.     int i,dy;
  76.  
  77.     dy = 0;
  78.     for(i=0; i<sdate->mo; ++i)
  79.     dy += mo_days_[i];      /* days in months */
  80.     if(!(sdate->yr%4)&&(sdate->mo>2))
  81.     ++dy;                   /* add for leap year */
  82.     return(dy + (sdate->dy));
  83. }
  84.  
  85.  
  86. /********
  87.  *
  88.  *   ut_daystr(day) - get pointer to day string
  89.  *
  90.  **/
  91.  
  92. char *ut_daystr(int day)
  93. {
  94.     extern char *dy_3names_[],*dy_names_[];
  95.  
  96.     if(dateoptf_&DDY3F)
  97.     return(dy_3names_[day]);
  98.     return(dy_names_[day]);
  99. }
  100.  
  101.  
  102. /********
  103.  *
  104.  *   ut_mostr(mo) - get pointer to month name string
  105.  *
  106.  **/
  107.  
  108. char *ut_mostr(int mo)
  109. {
  110.     extern char *mo_3names_[],*mo_names_[];
  111.  
  112.     if(dateoptf_&DMO3F)
  113.     return(mo_3names_[mo-1]);
  114.     return(mo_names_[mo-1]);
  115. }
  116.  
  117.  
  118. /********
  119.  *
  120.  *   ut_thismostr() - get this month to string
  121.  *
  122.  **/
  123.  
  124. char *ut_thismo(void)
  125. {
  126.     ut_gdate();             /* update it */
  127.     return(ut_mostr(month_));
  128. }
  129.  
  130.  
  131. /********
  132.  *
  133.  *   ut_todaystr() - return pointer to today's day of week
  134.  *
  135.  **/
  136.  
  137. char *ut_todaystr(void)
  138. {
  139.     return(ut_daystr(ut_today()));
  140. }
  141.  
  142.