示例#1
0
文件: ODATE.cpp 项目: AMDmi3/7kaa
//------------ Begin of function DateInfo::date_str ---------//
//
// Convert from julian date format to string date format
// Return a date string in the format of DD MMM YYYY e.g. 15 Jan 1992
//
// Julian day is the number of days since the date  Jan 1, 4713 BC
// Ex.  Jan 1, 1981 is  2444606
//
// <long> julianDate    = the julian date to be converted
// [int]  shortMonthStr = short month string or not (e.g. Jan instead of January)
//                        (default : 0)
//
// Return : <char*> the formated date string
//
char* DateInfo::date_str( long julianDate, int shortMonthStr)
{
   int    year, month, day, nDays, maxDays ;
   long   totalDays ;
   static char strBuf[16];

   if ( julianDate > 5373484 || julianDate < JULIAN_ADJUSTMENT )
   {
      strBuf[0]=0;
      return strBuf;
   }

   totalDays  =  (long) (julianDate) - JULIAN_ADJUSTMENT ;
   year       =  (int) ((double)totalDays/365.2425) + 1 ;
   nDays      =  (int) (totalDays -  ytoj(year)) ;

   if ( nDays <= 0 )
   {
      year-- ;
      nDays   =  (int) (totalDays - ytoj(year)) ;
   }

   if (year%4 == 0 && year%100 != 0 || year%400 == 0)
      maxDays =  366 ;
   else
      maxDays =  365 ;

   if ( nDays > maxDays )
   {
      year++ ;
      nDays -= maxDays ;
   }

   if ( month_day( year, nDays, month, day ) < 0 )
   {
      strBuf[0]=0;
      return strBuf;
   }

   //--------------------------------------------//

   static String str;

   if( shortMonthStr )
   {
      // TRANSLATORS: <Month> <Day>, <Year>
      snprintf(str, MAX_STR_LEN+1, _("%s %d, %d"), _(short_month_str_array[month-1]), day, year);
   }
   else
   {
      snprintf(str, MAX_STR_LEN+1, _("%s %d, %d"), _(month_str_array[month-1]), day, year);
   }

   return str;
}
示例#2
0
//------------ Begin of function DateInfo::get_date ---------//
//
// Return year, month or day of the given julian date
//
// <long> julianDate = the julian date to be converted
// <char> returnType = 'Y'-year, 'M'-month, 'D'-day
//
// Return : the year, month or day of the julian date
//          -1 if the julian date passed is invalid
//
int DateInfo::get_date( long julianDate, char returnType )
{
   int   year, month, day, nDays, maxDays ;
   long   totalDays ;

   if ( julianDate > 5373484 || julianDate < JULIAN_ADJUSTMENT )
      return -1;

   totalDays  =  (long) (julianDate) - JULIAN_ADJUSTMENT ;
   year       =  (int) ((double)totalDays/365.2425) + 1 ;
   nDays      =  (int) (totalDays -  ytoj(year)) ;

   if ( nDays <= 0 )
   {
      year-- ;
      nDays   =  (int) (totalDays - ytoj(year)) ;
   }

   if (year%4 == 0 && year%100 != 0 || year%400 == 0)
      maxDays =  366 ;
   else
      maxDays =  365 ;

   if ( nDays > maxDays )
   {
      year++ ;
      nDays -= maxDays ;
   }

   if ( month_day( year, nDays, month, day ) < 0 )
      return -1;

   //............................................//

   switch( returnType )
   {
      case 'Y':
         return year;

      case 'M':   // return the month
         return month;

      case 'D':
         return day;
   }

   return 0;
}
示例#3
0
//------------ Begin of function DateInfo::julain ----------//
//
// Convert from year, month, day integer format to julian date format
//
// Julian day is the number of days since the date  Jan 1, 4713 BC
// Ex.  Jan 1, 1981 is  2444606
//
// <int> year, month, day = the components of the date
//
// Return : <long> the julian date
//          -1     illegal given date
//
long DateInfo::julian( int year, int month, int day )
{
	long  total, dayYear ;

	dayYear    =  day_year( year, month, day) ;

	if (dayYear < 1)
		return( -1) ;  /* Illegal Date */

	total =  ytoj(year) ;
	total+=  dayYear ;
	total+=  JULIAN_ADJUSTMENT ;

	return total;
}
示例#4
0
//------------ Begin of function DateInfo::date_str ---------//
//
// Convert from julian date format to string date format
// Return a date string in the format of DD MMM YYYY e.g. 15 Jan 1992
//
// Julian day is the number of days since the date  Jan 1, 4713 BC
// Ex.  Jan 1, 1981 is  2444606
//
// <long> julianDate    = the julian date to be converted
// [int]  shortMonthStr = short month string or not (e.g. Jan instead of January)
//                        (default : 0)
//
// Return : <char*> the formated date string
//
char* DateInfo::date_str( long julianDate, int shortMonthStr)
{
   int    year, month, day, nDays, maxDays ;
   long   totalDays ;
   static char strBuf[16];

   if ( julianDate > 5373484 || julianDate < JULIAN_ADJUSTMENT )
   {
      strBuf[0]=NULL;
      return strBuf;
   }

   totalDays  =  (long) (julianDate) - JULIAN_ADJUSTMENT ;
   year       =  (int) ((double)totalDays/365.2425) + 1 ;
   nDays      =  (int) (totalDays -  ytoj(year)) ;

   if ( nDays <= 0 )
   {
      year-- ;
      nDays   =  (int) (totalDays - ytoj(year)) ;
   }

   if (year%4 == 0 && year%100 != 0 || year%400 == 0)
      maxDays =  366 ;
   else
      maxDays =  365 ;

   if ( nDays > maxDays )
   {
      year++ ;
      nDays -= maxDays ;
   }

   if ( month_day( year, nDays, month, day ) < 0 )
   {
      strBuf[0]=NULL;
      return strBuf;
   }

   //--------------------------------------------//

   static String str;

#if(defined(SPANISH))
	if( shortMonthStr )
	{
		str  = itoa(day,strBuf,10);		// day
		str += "-";
		strcpy(strBuf, translate.process(month_str_array[month-1]));
		if(strlen(strBuf) > 3)
			strBuf[3] = '\0';		// limit month to 3 chars
		str += strBuf;							// month
		str += "-";
	   str += itoa(year,strBuf,10);		// year
	}
	else
	{
		str  = itoa(day,strBuf,10);		// day
		str += " de ";
		str += translate.process(month_str_array[month-1]);
		str += " de ";
	   str += itoa(year,strBuf,10);		// year
	}
#elif(defined(FRENCH))
	str  = itoa(day,strBuf,10);		// day
	str += " ";
	if( shortMonthStr )
	{
		strcpy(strBuf, translate.process(month_str_array[month-1]));
		if(strlen(strBuf) > 3)
			strBuf[3] = '\0';		// limit month to 4 chars
		if(month == 7)				// Juillet(July) abbreviated to Jul.
			strBuf[2] = 'l';
		str += strBuf;							// month
	}
	else
	{
		str += translate.process(month_str_array[month-1]);
	}
	str += " ";
	str += itoa(year,strBuf,10);		// year
#else
	// GERMAN and US
	str = translate.process(month_str_array[month-1]);
   if( shortMonthStr )
      str = str.left(3);
   str += " ";
   str += itoa(day,strBuf,10);
   str += ", ";
   str += itoa(year,strBuf,10);
#endif

   return str;
}