home *** CD-ROM | disk | FTP | other *** search
/ PC World 1999 June / PCWorld_1999-06_cd.bin / Novinky / StarOff / english / prod_w95 / f_43965 / DATEFUNC.C
Encoding:
C/C++ Source or Header  |  1998-07-14  |  21.6 KB  |  867 lines

  1. /*------------------------------------------------------------------------
  2.  
  3. $Workfile:   Datefunc.c  $
  4.  
  5. $Header:   T:/sc/addin/datefunc/datefunc.c_v   1.1   13 Jul 1998 18:15:40   BEI  $
  6.  
  7. Description:    StarCalc Add-In Example ROT13
  8.  
  9. (c) Copyright 1998 - 2000, Star Division GmbH, Hamburg
  10.  
  11.  
  12. ------------------------------------------------------------------------*/
  13. static char datefunc_Id[]="@(#) StarCalc Datefunc Add-In (c) 1998-2000 STAR DIVISION GmbH, Hamburg";
  14.  
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include <math.h>
  18.  
  19. #include <addin.h>
  20.  
  21.  
  22. /**
  23.  * Defines for which Language the Addin is compiled.
  24.  * At the momment only english and german are provided for the example.
  25.  *
  26.  * 49 -> german
  27.  * everything else (default) -> english
  28.  *
  29.  */
  30. #ifndef LANGUAGE
  31. #define LANGUAGE 01
  32. #endif
  33.  
  34.  
  35. /**
  36.  * Null Date, initialized in GetFunctionCount
  37.  *
  38.  * StarCalc uses a BaseDate 12/30/1899
  39.  * If not specified otherwise in the Settings for the Spreedsheet Document.
  40.  *
  41.  * There's no way to get the Spreadsheet settings from whithin a simple addin,
  42.  * so this Addin can only be used by documents using the default BaseDate setting.
  43.  *
  44.  * The functions in this Addin use a BaseDate 01/01/0001
  45.  * The nNullDate Variable is the StarCalc BaseDate converted to
  46.  * this internal date representation.
  47.  *
  48.  * @see #GetFunctionCount
  49.  *
  50.  */
  51.  
  52. static ULONG nNullDate=0;
  53.  
  54. #define NULLDATE_Year  1899
  55. #define NULLDATE_Month 12
  56. #define NULLDATE_Day   30
  57.  
  58.  
  59. /**
  60.  * Array holding values for month length, used in DaysInMonth() function
  61.  *
  62.  * @see #DaysInMonth
  63.  *
  64.  */ 
  65. static USHORT aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,
  66.                                    31, 31, 30, 31, 30, 31 };
  67.  
  68.  
  69.  
  70. /**
  71.  * Check if a year is a leap year in the Gregorian calendar
  72.  *
  73.  * @param nYear the year which should be checked
  74.  * @return true if the year is a leap year, false otherwise.
  75.  *
  76.  * @see #DaysInMonth, #IsLeapYear, 
  77.  * @see #ScDate_DaysInMonth, #ScDate_IsLeapYear, #ScDate_WeeksInYear
  78.  *
  79.  */
  80. static BOOL IsLeapYear( USHORT nYear )
  81. {
  82.     return (((nYear % 4) == 0) && ((nYear % 100) != 0) || ((nYear % 400) == 0));
  83. }
  84.  
  85.  
  86. /**
  87.  * Get the number of days in a specified month
  88.  *
  89.  * @param nMonth the number of the Month
  90.  * @param nYear the year
  91.  * @return number of days
  92.  *
  93.  */
  94. static USHORT DaysInMonth( USHORT nMonth, USHORT nYear )
  95. {
  96.     if ( nMonth != 2 )
  97.         return aDaysInMonth[nMonth-1];
  98.     else
  99.     {
  100.         if ( IsLeapYear(nYear) )
  101.             return aDaysInMonth[nMonth-1] + 1;
  102.         else
  103.             return aDaysInMonth[nMonth-1];
  104.     }
  105. }
  106.  
  107.  
  108. /**
  109.  * Convert a date to a count of days starting from 01/01/0001
  110.  *
  111.  * The internal representation of a Date used in this Addin
  112.  * is the number of days between 01/01/0001 and the date
  113.  * this function converts a Day , Month, Year representation
  114.  * to this internal Date value.
  115.  * 
  116.  * @param nDay the day of the Month
  117.  * @param nMonth the number of the Month
  118.  * @param nYear the Year
  119.  * @return count of days from 01/01/0001 to the date specified
  120.  *
  121.  */
  122. static long DateToDays( USHORT nDay, USHORT nMonth, USHORT nYear )
  123. {
  124.     long nDays;
  125.     USHORT i;
  126.  
  127.     nDays = ((ULONG)nYear-1) * 365;
  128.     nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);
  129.  
  130.     for( i = 1; i < nMonth; i++ )
  131.         nDays += DaysInMonth(i,nYear);
  132.     nDays += nDay;
  133.  
  134.     return nDays;
  135. }
  136.  
  137.  
  138. /**
  139.  * Convert a count of days starting from 01/01/0001 to a date
  140.  *
  141.  * The internal representation of a Date used in this Addin
  142.  * is the number of days between 01/01/0001 and the date
  143.  * this function converts this internal Date value
  144.  * to a Day , Month, Year representation of a Date.
  145.  *
  146.  * @param nDay count of days from 01/01/0001
  147.  * @param *pDay pointer to a variable for the day of the month
  148.  * @param *pMonth pointer to a variable for the month
  149.  * @param *pYear pointer to a variable for the year
  150.  *
  151.  */
  152. static void DaysToDate( long nDays,
  153.                         USHORT *pDay, USHORT *pMonth, USHORT *pYear )
  154. {
  155.     long    nTempDays;
  156.     long    i = 0;
  157.     BOOL    bCalc;
  158.  
  159.     do
  160.     {
  161.         nTempDays = (long)nDays;
  162.         *pYear = (USHORT)((nTempDays / 365) - i);
  163.         nTempDays -= ((ULONG) *pYear -1) * 365;
  164.         nTempDays -= (( *pYear -1) / 4) - (( *pYear -1) / 100) + ((*pYear -1) / 400);
  165.         bCalc = FALSE;
  166.         if ( nTempDays < 1 )
  167.         {
  168.             i++;
  169.             bCalc = TRUE;
  170.         }
  171.         else
  172.         {
  173.             if ( nTempDays > 365 )
  174.             {
  175.                 if ( (nTempDays != 366) || !IsLeapYear( *pYear ) )
  176.                 {
  177.                     i--;
  178.                     bCalc = TRUE;
  179.                 }
  180.             }
  181.         }
  182.     }
  183.     while ( bCalc );
  184.  
  185.     *pMonth = 1;
  186.     while ( (ULONG)nTempDays > DaysInMonth( *pMonth, *pYear ) )
  187.     {
  188.         nTempDays -= DaysInMonth( *pMonth, *pYear );
  189.         (*pMonth)++;
  190.     }
  191.     *pDay = (USHORT)nTempDays;
  192. }
  193.  
  194. /**
  195.  * Get week difference between 2 dates
  196.  * 
  197.  * new Weeks(date1,date2,mode) function for StarCalc
  198.  *
  199.  * Two modes of operation are provided. 
  200.  * The first is just a simple division by 7 calculation.
  201.  *
  202.  * The second calculates the diffence by week of year.
  203.  * 
  204.  * The International Standard IS-8601 has decreed that Monday 
  205.  * shall be the first day of the week.
  206.  *
  207.  * A week that lies partly in one year and partly in annother
  208.  * is assigned a number in the the year in which most of its days lie.
  209.  *
  210.  * That means that week 1 of any year is the week that contains the 4. January
  211.  *
  212.  * The internal representation of a Date used in the Addin is the number of days based on 01/01/0001
  213.  *
  214.  * A WeekDay can be then calculated by substracting 1 and calculating the rest of
  215.  * a division by 7, which gives a 0 - 6 value for Monday - Sunday
  216.  *
  217.  * Using the 4. January rule explained above the formula
  218.  *
  219.  *    nWeek1= ( nDays1 - nJan4 + ( (nJan4-1) % 7 ) ) / 7 + 1;
  220.  *
  221.  * calculates a number between 0-53 for each day which is in the same year as nJan4
  222.  * where 0 means that this week belonged to the year before.
  223.  *
  224.  * If a day in the same or annother year is used in this formula this calculates
  225.  * an calendar week offset from a given 4. January
  226.  *
  227.  *    nWeek2 = ( nDays2 - nJan4 + ( (nJan4-1) % 7 ) ) / 7 + 1;
  228.  *
  229.  * The 4.January of first Date Argument can thus be used to calculate 
  230.  * the week difference by calendar weeks which is then nWeek = nWeek2 - nWeek1
  231.  *
  232.  * which can be optimized to
  233.  *
  234.  * nWeek = ( (nDays2-nJan4+((nJan4-1)%7))/7 ) - ( (nDays1-nJan4+((nJan4-1)%7))/7 )
  235.  * 
  236.  * Note: All calculations are operating on the long integer data type
  237.  * % is the modulo operator in C which calculates the rest of an Integer division
  238.  *
  239.  *
  240.  * @param *r - return value for the StarCalc function
  241.  * @param d1 - date value (in StarCalc representation based 12/30/1899), usually the older date
  242.  * @param d2 - date value (in StarCalc representation based 12/30/1899), usually the younger date
  243.  * @param dMode - mode of operation
  244.  *
  245.  * mode 0 is the interval between the dates in month, that is days / 7
  246.  *
  247.  * mode 1 is the difference by week of year
  248.  *
  249.  */
  250. void CALLTYPE ScDate_GetDiffWeeks(double *r, double *d1, double *d2, double *dMode)
  251. {
  252.   long nDays1=0;
  253.   long nDays2=0;
  254.   int nMode=0;
  255.  
  256.   if ( d1 ) nDays1=(long)floor(*d1)+nNullDate;
  257.   if ( d2 ) nDays2=(long)floor(*d2)+nNullDate;
  258.  
  259.  
  260.   if ( dMode) nMode=(int)*dMode;
  261.  
  262.   if ( nMode == 1 ) {
  263.  
  264.     USHORT nDay,nMonth,nYear;
  265.     long nJan4;
  266.  
  267.     DaysToDate(nDays1,&nDay,&nMonth,&nYear);
  268.     nJan4=DateToDays(4,1,nYear);
  269.  
  270.     *r=(double) ( ( (nDays2-nJan4+((nJan4-1)%7))/7 ) - ( (nDays1-nJan4+((nJan4-1)%7))/7 ) );
  271.     
  272.   } else {
  273.  
  274.     *r= (double) ( (nDays2 - nDays1) / 7 ) ;
  275.   }
  276.   
  277. }
  278.  
  279. /**
  280.  * Get month difference between 2 dates
  281.  * =Month(start, end, mode) Function for StarCalc
  282.  *
  283.  * two modes are provided 
  284.  *
  285.  * @param *r - return value for the StarCalc function
  286.  * @param d1 - date value, start date
  287.  * @param d2 - date value, end date
  288.  * @param dMode - mode of operation
  289.  *
  290.  * mode 0 is the interval between the dates in month
  291.  *
  292.  * mode 1 is the difference in calendar month
  293.  *
  294.  */
  295. void CALLTYPE ScDate_GetDiffMonths(double *r, double *d1, double *d2, double *dMode)
  296. {
  297.   USHORT nDay1,nMonth1,nYear1;
  298.   USHORT nDay2,nMonth2,nYear2;
  299.   long nDays1=0;
  300.   long nDays2=0;
  301.   int nMode=0;
  302.  
  303.   if ( dMode) nMode=(int)*dMode;
  304.  
  305.   if ( d1 ) nDays1=(long)floor(*d1)+nNullDate;
  306.   if ( d2 ) nDays2=(long)floor(*d2)+nNullDate;
  307.  
  308.   DaysToDate(nDays1,&nDay1,&nMonth1,&nYear1);
  309.   DaysToDate(nDays2,&nDay2,&nMonth2,&nYear2);
  310.   
  311.   *r=(double) ( nMonth2 - nMonth1 + (nYear2 - nYear1) * 12 );
  312.   if ( nMode == 1 || nDays1 == nDays2 ) return;
  313.  
  314.   if ( nDays1 < nDays2 ) {
  315.     if ( nDay1 > nDay2 ) {
  316.         *r -= 1;    
  317.     }
  318.   } else {
  319.     if ( nDay1 < nDay2 ) {
  320.         *r += 1;    
  321.     }
  322.   }
  323.  
  324. }
  325.  
  326.  
  327. /**
  328.  * Get Year difference between 2 dates
  329.  *
  330.  * two modes are provided 
  331.  *
  332.  * @param *r - return value for the StarCalc function
  333.  * @param d1 - date value, start date
  334.  * @param d2 - date value, end date
  335.  * @param dMode - mode of operation
  336.  *
  337.  * mode 0 is the interval between the dates in years
  338.  *
  339.  * mode 1 is the difference in calendar years
  340.  *
  341.  */
  342. void CALLTYPE ScDate_GetDiffYears(double *r, double *d1, double *d2, double *dMode)
  343. {
  344.   USHORT nDay1,nMonth1,nYear1;
  345.   USHORT nDay2,nMonth2,nYear2;
  346.   long nDays1=0;
  347.   long nDays2=0;
  348.   int nMode=0;
  349.  
  350.   if ( dMode) nMode=(int)*dMode;
  351.  
  352.   if ( d1 ) nDays1=(long)floor(*d1)+nNullDate;
  353.   if ( d2 ) nDays2=(long)floor(*d2)+nNullDate;
  354.  
  355.   DaysToDate(nDays1,&nDay1,&nMonth1,&nYear1);
  356.   DaysToDate(nDays2,&nDay2,&nMonth2,&nYear2);
  357.   if ( nMode != 1 ) {
  358.     ScDate_GetDiffMonths(r,d1,d2,dMode);
  359.     *r= (double) ( ((int) *r) / 12 );
  360.   } else {
  361.       *r=(double) ( nYear2 - nYear1 );
  362.   }
  363. }
  364.  
  365. /**
  366.  * Check if a Date is in a leap year in the Gregorian calendar
  367.  *
  368.  * @param *r - return value for the StarCalc function
  369.  * @param d - date value (in StarCalc representation based 12/30/1899)
  370.  *
  371.  */
  372. void CALLTYPE ScDate_IsLeapYear(double *r, double *d)
  373. {
  374.   ULONG nDays;
  375.   USHORT nDay, nMonth, nYear;
  376.   double v=0.0;
  377.  
  378.   if ( d ) v=*d;
  379.   nDays=(int) v + nNullDate;
  380.  
  381.   DaysToDate(nDays,&nDay,&nMonth,&nYear);
  382.  
  383.   *r=(double) ( IsLeapYear(nYear) );
  384.  
  385. }
  386.  
  387. /**
  388.  * Get the Number of Days in the month for a date
  389.  * 
  390.  * @param *r - return value for the StarCalc function
  391.  * @param d - date value (in StarCalc representation based 12/30/1899)
  392.  *
  393.  */
  394. void CALLTYPE ScDate_DaysInMonth(double *r, double *d)
  395. {
  396.   ULONG nDays;
  397.   USHORT nDay, nMonth, nYear;
  398.   double v=0.0;
  399.  
  400.   if ( d ) v=*d;
  401.   nDays=(int) v + nNullDate;
  402.  
  403.   DaysToDate(nDays,&nDay,&nMonth,&nYear);
  404.   *r=(double) ( DaysInMonth( nMonth, nYear) );
  405.  
  406. }
  407.  
  408.  
  409. /**
  410.  * Get number of weeks in the year for a date
  411.  *
  412.  * Most years have 52 weeks, but years that start on a Thursday
  413.  * and leep years that start on a Wednesday have 53 weeks
  414.  *
  415.  * The International Standard IS-8601 has decreed that Monday 
  416.  * shall be the first day of the week.
  417.  *
  418.  * A WeekDay can be calculated by substracting 1 and calculating the rest of
  419.  * a division by 7 from the internal date represention
  420.  * which gives a 0 - 6 value for Monday - Sunday
  421.  *
  422.  * @param *r - return value for the StarCalc function
  423.  * @param d - date value (in StarCalc represantaion based 30.12.1899)
  424.  *
  425.  * @see #IsLeapYear #WeekNumber  
  426.  *
  427.  */
  428. void CALLTYPE ScDate_WeeksInYear(double *r, double *d)
  429. {
  430.   ULONG nDays;
  431.   USHORT nDay, nMonth, nYear;
  432.   double v=0.0;
  433.   long nJan1WeekDay;
  434.  
  435.   if ( d ) v=*d;
  436.   nDays=(int) v + nNullDate;
  437.  
  438.   DaysToDate(nDays,&nDay,&nMonth,&nYear);
  439.  
  440.   nJan1WeekDay= ( DateToDays(1,1,nYear) - 1) % 7;
  441.  
  442.   if ( nJan1WeekDay == 3 ) { /* Thursday */
  443.     *r=(double) 53;
  444.     return;
  445.   } else if ( nJan1WeekDay == 2 ) { /* Wednesday */
  446.     *r= (double) ( IsLeapYear(nYear) ? 53 : 52 );
  447.   } else {
  448.     *r= (double) 52;
  449.   }
  450. }
  451.  
  452.  
  453. /**
  454.  * Get number of days in the year of a date specified
  455.  *
  456.  * @param *r - return value for the StarCalc function
  457.  * @param d - date value (in StarCalc represantaion based 30.12.1899)
  458.  *
  459.  */
  460. void CALLTYPE ScDate_DaysInYear(double *r, double *d)
  461. {
  462.   ULONG nDays;
  463.   USHORT nDay, nMonth, nYear;
  464.   double v=0.0;
  465.  
  466.   if ( d ) v=*d;
  467.   nDays=(int) v + nNullDate;
  468.  
  469.   DaysToDate(nDays,&nDay,&nMonth,&nYear);
  470.   *r=(double) ( IsLeapYear(nYear) ? 366 : 365 );
  471.  
  472. }
  473.  
  474.  
  475. /*
  476.  * Tell StarCalc how many new functions this Addin provides.
  477.  *
  478.  * It's called before any of these new functions is actually
  479.  * executed and is also used to initialize the NullDate here.
  480.  *
  481.  * StarCalc uses a Date Base 12/30/1899
  482.  * If not specified otherwise in the Options for the Spreedsheet Document
  483.  *
  484.  *
  485.  * @param *nCount - returns the number of functions which are exported to StarCalc
  486.  *
  487.  */
  488. void CALLTYPE GetFunctionCount( USHORT *nCount )
  489. {
  490.  
  491.   /* initialize nNullDate Value 0 is 12/30/1899 */
  492.   nNullDate=DateToDays(NULLDATE_Day, NULLDATE_Month, NULLDATE_Year);
  493.  
  494.   *nCount = 7;
  495. }
  496.  
  497. /*
  498.  * Provides neccessary data for each new function to StarCalc
  499.  *
  500.  * @param *nNo Input: Function number between 0 and nCount - 1
  501.  * @param *pFuncName Output: Functionname which should be called in the AddIn-DLL
  502.  * @param *nParamCount Output: Number of Parameter. Must be greater than 0, because there's always a return-Value. Maximum is 16.
  503.  * @param *Paramtype* peType Output: Pointer to arrray with exactly 16 variables of typ Paramtype. nParamCount Entries are set to the type of the corresponding Parameters.
  504.  * @param *pInternalName Output: Functionname as seen by the Spreadsheet user
  505.  *
  506.  * @see #GetFunctionCount, #GetParameterDescription
  507.  *
  508.  */
  509.  
  510. void CALLTYPE GetFunctionData( USHORT *    nNo,
  511.                                char *      pFuncName,
  512.                                USHORT *    nParamCount,
  513.                                ParamType * peType,
  514.                                char *      pInternalName )
  515. {
  516.  
  517.  
  518.      switch( *nNo ) {
  519.      case 0:
  520.  
  521. #if LANGUAGE == 49
  522.      strcpy( pInternalName, "Wochen" );
  523. #else
  524.      strcpy( pInternalName, "Weeks" );
  525. #endif
  526.  
  527.      strcpy( pFuncName,     "ScDate_GetDiffWeeks" );
  528.      peType[0] = PTR_DOUBLE;
  529.      peType[1] = PTR_DOUBLE;
  530.      peType[2] = PTR_DOUBLE;
  531.      peType[3] = PTR_DOUBLE;
  532.      *nParamCount=4;
  533.      break;
  534.  
  535.      case 1:
  536. #if LANGUAGE == 49
  537.      strcpy( pInternalName, "Monate" );
  538. #else
  539.      strcpy( pInternalName, "Months" );
  540. #endif
  541.      strcpy( pFuncName,     "ScDate_GetDiffMonths" );
  542.  
  543.      peType[0] = PTR_DOUBLE;
  544.      peType[1] = PTR_DOUBLE;
  545.      peType[2] = PTR_DOUBLE;
  546.      peType[3] = PTR_DOUBLE;
  547.      *nParamCount=4;
  548.      break;
  549.  
  550.      case 2:
  551. #if LANGUAGE == 49
  552.      strcpy( pInternalName, "Jahre" );
  553. #else
  554.      strcpy( pInternalName, "Years" );
  555. #endif
  556.      strcpy( pFuncName,     "ScDate_GetDiffYears" );
  557.      peType[0] = PTR_DOUBLE;
  558.      peType[1] = PTR_DOUBLE;
  559.      peType[2] = PTR_DOUBLE;
  560.      peType[3] = PTR_DOUBLE;
  561.      *nParamCount=4;
  562.      break;
  563.  
  564.      case 3:
  565. #if LANGUAGE == 49
  566.      strcpy( pInternalName, "IstSchaltJahr" );
  567. #else
  568.      strcpy( pInternalName, "IsLeapYear" );
  569. #endif
  570.  
  571.      strcpy( pFuncName,     "ScDate_IsLeapYear" );
  572.      peType[0] = PTR_DOUBLE;
  573.      peType[1] = PTR_DOUBLE;
  574.      *nParamCount=2;
  575.      break;
  576.  
  577.      case 4:
  578. #if LANGUAGE == 49
  579.      strcpy( pInternalName, "TageImMonat" );
  580. #else
  581.      strcpy( pInternalName, "DaysInMonth" );
  582. #endif
  583.  
  584.      strcpy( pFuncName,     "ScDate_DaysInMonth" );
  585.      peType[0] = PTR_DOUBLE;
  586.      peType[1] = PTR_DOUBLE;
  587.      *nParamCount=2;
  588.      break;
  589.  
  590.      case 5:
  591. #if LANGUAGE == 49
  592.      strcpy( pInternalName, "TageImJahr" );
  593. #else
  594.      strcpy( pInternalName, "DaysInYear" );
  595. #endif
  596.  
  597.      strcpy( pFuncName,     "ScDate_DaysInYear" );
  598.      peType[0] = PTR_DOUBLE;
  599.      peType[1] = PTR_DOUBLE;
  600.      *nParamCount=2;
  601.      break;
  602.  
  603.      case 6:
  604. #if LANGUAGE == 49
  605.      strcpy( pInternalName, "WochenImJahr" );
  606. #else
  607.      strcpy( pInternalName, "WeeksInYear" );
  608. #endif
  609.  
  610.      strcpy( pFuncName,     "ScDate_WeeksInYear" );
  611.      peType[0] = PTR_DOUBLE;
  612.      peType[1] = PTR_DOUBLE;
  613.      *nParamCount=2;
  614.      break;
  615.  
  616.      default:
  617.             *nParamCount    = 0;
  618.             *pFuncName     = 0;
  619.             *pInternalName = 0;
  620.             break;
  621.     }
  622. }
  623.  
  624. /**
  625.  * Provides descriptions for each new function to StarCalc
  626.  * which are shown is the autopilot
  627.  *
  628.  * @param *nNo Input Parameter, Function number between 0 and nCount - 1
  629.  * @param *p
  630.  *
  631.  * @see #GetFunctionCount, #GetParameterDescription
  632.  */
  633. void CALLTYPE GetParameterDescription( USHORT* nNo, USHORT* nParam, 
  634. char* pName, char* pDesc )
  635. {
  636.     *pName = 0;
  637.     *pDesc = 0;
  638.  
  639. #if LANGUAGE == 49
  640.     switch ( *nNo ) {
  641.     case 0:    /* Weeks */
  642.         switch ( *nParam ) {
  643.         case 0:
  644.             strcpy(pDesc,"Bestimmt die Wochendifferenz zweier Daten");
  645.             break;
  646.         case 1:
  647.             strcpy(pName,"Datum 1");
  648.             strcpy(pDesc,"Jⁿngeres Datum fⁿr die Wochendifferenz");
  649.             break;
  650.         case 2:
  651.             strcpy(pName,"Datum 2");
  652.             strcpy(pDesc,"─lteres Datum fⁿr die Wochendifferenz");
  653.             break;
  654.         case 3:
  655.             strcpy(pName,"Art");
  656.             strcpy(pDesc,"Art der Differenzbildung Art=0 hei▀t Intervall, Art=1 hei▀t in Kalenderwochen");
  657.             break;
  658.         }
  659.         break;
  660.     case 1: /* Months */
  661.         switch ( *nParam ) {
  662.         case 0:
  663.             strcpy(pDesc,"Bestimmt die Monatsdifferenz zweier Daten");
  664.             break;
  665.         case 1:
  666.             strcpy(pName,"Datum 1");
  667.             strcpy(pDesc,"Jⁿngeres Datum fⁿr die Monatsdifferenz");
  668.             break;
  669.         case 2:
  670.             strcpy(pName,"Datum 2");
  671.             strcpy(pDesc,"─lteres Datum fⁿr die Monatsdifferenz");
  672.             break;
  673.         case 3:
  674.             strcpy(pName,"Art");
  675.             strcpy(pDesc,"Art der Differenzbildung Art=0 hei▀t Intervall, Art=1 hei▀t in Kalendermonaten");
  676.             break;
  677.         }
  678.         break;
  679.     case 2: /* Years */
  680.         switch ( *nParam ) {
  681.         case 0:
  682.             strcpy(pDesc,"Bestimmt die Jahresdifferenz zweier Daten");
  683.             break;
  684.         case 1:
  685.             strcpy(pName,"Datum 1");
  686.             strcpy(pDesc,"Jⁿngeres Datum fⁿr die Monatsdifferenz");
  687.             break;
  688.         case 2:
  689.             strcpy(pName,"Datum 2");
  690.             strcpy(pDesc,"─lteres Datum fⁿr die Monatsdifferenz");
  691.             break;
  692.         case 3:
  693.             strcpy(pName,"Art");
  694.             strcpy(pDesc,"Art der Differenzbildung Art=0 hei▀t Intervall, Art=1 hei▀t in Kalenderjahren");
  695.             break;
  696.         }
  697.        break;
  698.     case 3:    /* IsLeapYear */
  699.         switch ( *nParam ) {
  700.         case 0:
  701.             strcpy(pDesc,"Liefert 1(WAHR) wenn das Jahr ein Schaltjahr ist sonst 0(FALSCH)");
  702.             break;
  703.         case 1:
  704.             strcpy(pName,"Datum");
  705.             strcpy(pDesc,"Interne Zahl des Datums"); /* StarCalc Value */
  706.             break;
  707.         }
  708.         break;
  709.     case 4:    /* DaysInMonth */
  710.         switch ( *nParam ) {
  711.         case 0:
  712.             strcpy(pDesc,"Bestimmt die Anzahl an Tagen im Monat zu einem Datum");
  713.             break;
  714.         case 1:
  715.             strcpy(pName,"Datum");
  716.             strcpy(pDesc,"Interne Zahl des Datums"); /* StarCalc Value */
  717.             break;
  718.         }
  719.         break;
  720.     case 5:    /* DaysInYear */
  721.         switch ( *nParam ) {
  722.         case 0:
  723.             strcpy(pDesc,"Bestimmt die Anzahl an Tagen im Jahr zu einem Datum");
  724.             break;
  725.         case 1:
  726.             strcpy(pName,"Datum");
  727.             strcpy(pDesc,"Interne Zahl des Datums"); /* StarCalc Value */
  728.             break;
  729.         }
  730.         break;
  731.  
  732.     case 6:    /* WeeksInYear */
  733.         switch ( *nParam ) {
  734.         case 0:
  735.             strcpy(pDesc,"Bestimmt die Anzahl an Wochen im Jahr zu einem Datum");
  736.             break;
  737.         case 1:
  738.             strcpy(pName,"Datum");
  739.             strcpy(pDesc,"Interne Zahl des Datums"); /* StarCalc Value */
  740.             break;
  741.         }
  742.         break;
  743.     }
  744.  
  745. #else    
  746.  
  747.     switch ( *nNo ) {
  748.     case 0:    /* Weeks */
  749.         switch ( *nParam ) {
  750.         case 0:
  751.             strcpy(pDesc,"returns number of weeks between two dates");
  752.             break;
  753.         case 1:
  754.             strcpy(pName,"Date 1");
  755.             strcpy(pDesc,"the older date");
  756.             break;
  757.         case 2:
  758.             strcpy(pName,"Date 2");
  759.             strcpy(pDesc,"the younger date");
  760.             break;
  761.         case 3:
  762.             strcpy(pName,"Mode");
  763.             strcpy(pDesc,"Mode=0 means week interval, Mode=1 means by week of year ");
  764.             break;
  765.         }
  766.         break;
  767.     case 1: /* Months */
  768.         switch ( *nParam ) {
  769.             strcpy(pDesc,"returns number of month between two dates");
  770.             break;
  771.         case 1:
  772.             strcpy(pName,"Date 1");
  773.             strcpy(pDesc,"the older date");
  774.             break;
  775.         case 2:
  776.             strcpy(pName,"Date 2");
  777.             strcpy(pDesc,"the younger date");
  778.             break;
  779.         case 3:
  780.             strcpy(pName,"Mode");
  781.             strcpy(pDesc,"Mode=0 means month interval, Mode=1 means by month of year");
  782.             break;
  783.         }
  784.         break;
  785.     case 2: /* Years */
  786.         switch ( *nParam ) {
  787.             strcpy(pDesc,"returns number of years between two dates");
  788.             break;
  789.         case 1:
  790.             strcpy(pName,"Date 1");
  791.             strcpy(pDesc,"the older date");
  792.             break;
  793.         case 2:
  794.             strcpy(pName,"Date 2");
  795.             strcpy(pDesc,"the younger date");
  796.             break;
  797.         case 3:
  798.             strcpy(pName,"Mode");
  799.             strcpy(pDesc,"Mode=0 means year interval, Mode=1 means by calendar years");
  800.             break;
  801.         }
  802.        break;
  803.     case 3:    /* IsLeapYear */
  804.         switch ( *nParam ) {
  805.         case 0:
  806.             strcpy(pDesc,"returns 1 if the date is in a LeapYear, 0 otherwise");
  807.             break;
  808.         case 1:
  809.             strcpy(pName,"Date");
  810.             strcpy(pDesc,"a internal date value"); /* StarCalc Value */
  811.             break;
  812.         }
  813.         break;
  814.     case 4:    /* DaysInMonth */
  815.         switch ( *nParam ) {
  816.         case 0:
  817.             strcpy(pDesc,"returns the number of days in the month for a date");
  818.             break;
  819.         case 1:
  820.             strcpy(pName,"Date");
  821.             strcpy(pDesc,"a internal date value"); /* StarCalc Value */
  822.             break;
  823.         }
  824.         break;
  825.     case 5:    /* DaysInYear */
  826.         switch ( *nParam ) {
  827.         case 0:
  828.             strcpy(pDesc,"returns the number of days in the year for a date");
  829.             break;
  830.         case 1:
  831.             strcpy(pName,"Date");
  832.             strcpy(pDesc,"a internal date value"); /* StarCalc Value */
  833.             break;
  834.         }
  835.         break;
  836.  
  837.     case 6:    /* WeeksInYear */
  838.         switch ( *nParam ) {
  839.         case 0:
  840.             strcpy(pDesc,"returns the number of weeks in the year for a date");
  841.             break;
  842.         case 1:
  843.             strcpy(pName,"Date");
  844.             strcpy(pDesc,"a internal date value"); /* StarCalc Value */
  845.             break;
  846.         }
  847.         break;
  848.     }
  849.  
  850. #endif
  851.  
  852. }
  853.  
  854. /*------------------------------------------------------------------------
  855.  
  856. $Log:   T:/sc/addin/datefunc/datefunc.c_v  $
  857.    
  858.       Rev 1.1   13 Jul 1998 18:15:40   BEI
  859.    2 Languages
  860.    
  861.       Rev 1.0   07 Jul 1998 20:36:22   NN
  862.    Initial revision.
  863.  
  864. ------------------------------------------------------------------------*/
  865.  
  866.  
  867.