21#include <com/sun/star/util/DateTime.hpp>
37 SAL_WARN_IF( nYear == 0 && !(nYear == 0 && nMonth == 0 && nDay == 0),
38 "tools.datetime",
"Date::setDateFromDMY - sure about 0 year? It's not in the calendar.");
39 assert( nMonth < 100 &&
"nMonth % 100 not representable" );
40 assert( nDay < 100 &&
"nDay % 100 not representable" );
43 (
static_cast<sal_Int32
>( nYear ) * 10000) -
44 (
static_cast<sal_Int32
>( nMonth % 100 ) * 100) -
45 static_cast<sal_Int32
>( nDay % 100 );
48 (
static_cast<sal_Int32
>( nYear ) * 10000) +
49 (
static_cast<sal_Int32
>( nMonth % 100 ) * 100) +
50 static_cast<sal_Int32
>( nDay % 100 );
55 assert( ((nNewDate / 10000) != 0) &&
"you don't want to set a 0 year, do you?" );
62 SAL_WARN_IF( nMonth < 1 || 12 < nMonth,
"tools.datetime",
"Date::GetDaysInMonth - nMonth out of bounds " << nMonth);
77 assert(nDays == 693594);
83 sal_uInt16 nDay =
GetDay();
101 return Date( nDay, nMonth, nYear);
127 assert( nNewYear != 0 );
174 sal_Int32 nMonths =
GetMonth() + nAddMonths;
175 sal_Int32 nNewMonth = nMonths % 12;
176 sal_Int32 nYear =
GetYear() + nMonths / 12;
177 if( nMonths <= 0 || nNewMonth == 0 )
182 nYear = (nAddMonths < 0 ? -1 : 1);
187 SetMonth(
static_cast<sal_uInt16
>(nNewMonth) );
188 SetYear(
static_cast<sal_Int16
>(nYear) );
199 sal_uInt16 nDay =
GetDay();
204 for( sal_uInt16
i = 1;
i < nMonth;
i++ )
210 sal_Int16 nMinimumNumberOfDaysInWeek )
const
213 short n1WDay =
static_cast<short>(
Date( 1, 1,
GetYear() ).GetDayOfWeek());
219 n1WDay = (n1WDay+(7-
static_cast<short>(eStartDay))) % 7;
221 if (nMinimumNumberOfDaysInWeek < 1 || 7 < nMinimumNumberOfDaysInWeek)
223 SAL_WARN(
"tools.datetime",
"Date::GetWeekOfYear: invalid nMinimumNumberOfDaysInWeek" );
224 nMinimumNumberOfDaysInWeek = 4;
227 if ( nMinimumNumberOfDaysInWeek == 1 )
229 nWeek = ((n1WDay+nDayOfYear)/7) + 1;
234 else if ( nWeek == 53 )
237 short nDaysNextYear =
static_cast<short>(
Date( 1, 1,
GetNextYear() ).GetDayOfWeek());
238 nDaysNextYear = (nDaysNextYear+(7-
static_cast<short>(eStartDay))) % 7;
239 if ( nDayOfYear > (nDaysInYear-nDaysNextYear-1) )
243 else if ( nMinimumNumberOfDaysInWeek == 7 )
245 nWeek = ((n1WDay+nDayOfYear)/7);
250 nWeek = aLastDatePrevYear.
GetWeekOfYear( eStartDay, nMinimumNumberOfDaysInWeek );
256 if ( n1WDay < nMinimumNumberOfDaysInWeek )
259 else if ( n1WDay == nMinimumNumberOfDaysInWeek )
262 else if ( n1WDay == nMinimumNumberOfDaysInWeek + 1 )
274 if ( (nWeek == 1) || (nDayOfYear + n1WDay > 6) )
277 nWeek += (nDayOfYear + n1WDay) / 7;
279 nWeek = (nDayOfYear + n1WDay) / 7;
286 nTempDays += 6 - (
GetDayOfWeek()+(7-
static_cast<short>(eStartDay))) % 7;
292 return static_cast<sal_uInt16
>(nWeek);
297 sal_uInt16 nDay =
GetDay();
313 sal_uInt16 nDay =
GetDay();
317 if ( !nMonth || (nMonth > 12) )
321 else if ( nYear <= 1582 )
325 else if ( nMonth < 10 )
327 else if ( (nMonth == 10) && (nDay < 15) )
359 sal_uInt16 nDay =
GetDay();
Represents a date in the proleptic Gregorian calendar.
bool IsValidDate() const
If the represented date is valid (1<=month<=12, 1<=day<=(28,29,30,31) depending on month/year)
sal_uInt16 GetDayOfYear() const
Obtain the day of the year for the date.
void SetDate(sal_Int32 nNewDate)
sal_uInt16 GetDaysInYear() const
sal_Int32 GetAsNormalizedDays() const
An accelerated form of DateToDays on this date.
sal_uInt16 GetWeekOfYear(DayOfWeek eStartDay=MONDAY, sal_Int16 nMinimumNumberOfDaysInWeek=4) const
Obtain the week of the year for a date.
void setDateFromDMY(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
sal_Int16 GetNextYear() const
void AddDays(sal_Int32 nAddDays)
Add days skipping year 0 and truncating at limits.
bool IsValidAndGregorian() const
If the represented date is valid (1<=month<=12, 1<=day<=(28,29,30,31) depending on month/year) AND is...
sal_Int16 GetYear() const
sal_uInt16 GetDay() const
sal_Int16 GetPrevYear() const
sal_uInt16 GetDaysInMonth() const
Obtain the number of days in the month of the year of the date.
bool IsEndOfMonth() const
void AddYears(sal_Int16 nAddYears)
Add years skipping year 0 and truncating at limits.
void SetMonth(sal_uInt16 nNewMonth)
nNewMonth must be <100
void SetYear(sal_Int16 nNewYear)
nNewYear must be != 0
void Normalize()
Normalize date, invalid day or month values are adapted such that they carry over to the next month o...
static sal_Int32 DateToDays(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
Internally normalizes values.
DayOfWeek GetDayOfWeek() const
Obtain the day of the week for the date.
void AddMonths(sal_Int32 nAddMonths)
Add months skipping year 0 and truncating at limits.
void SetDay(sal_uInt16 nNewDay)
nNewDay must be <100
sal_uInt16 GetMonth() const
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
constexpr sal_uInt16 getDaysInMonth(sal_uInt16 nMonth, sal_Int16 nYear)
constexpr bool isLeapYear(sal_Int16 nYear)
constexpr sal_Int16 kYearMax
void convertDaysToDate(sal_Int32 nDays, sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_Int16 &rYear)
bool isValidDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
constexpr sal_Int16 kYearMin
constexpr sal_Int32 convertDateToDays(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
bool normalize(sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_Int16 &rYear)
sal_Int32 convertDateToDaysNormalizing(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
bool GetSystemDateTime(sal_Int32 *pDate, sal_Int64 *pTime)
Get current local timestamp.
static Date lcl_DaysToDate(sal_Int32 nDays)
Date operator-(const Date &rDate, sal_Int32 nDays)
Date operator+(const Date &rDate, sal_Int32 nDays)