KCalendarSystem Class Reference
from PyKDE4.kdecore import *
Detailed Description
- Abstract class:
- This class can be used as a base class for new classes, but can not be instantiated directly.
KCalendarSystem abstract base class, provides support for local Calendar Systems in KDE
Derived classes must be created through the create() static method
Enumerations | |
MonthNameFormat | { ShortName, LongName, ShortNamePossessive, LongNamePossessive } |
StringFormat | { ShortFormat, LongFormat } |
WeekDayNameFormat | { ShortDayName, LongDayName } |
Methods | |
__init__ (self, KLocale locale=0) | |
__init__ (self, KCalendarSystem a0) | |
QDate | addDays (self, QDate date, int ndays) |
QDate | addMonths (self, QDate date, int nmonths) |
QDate | addYears (self, QDate date, int nyears) |
QString | calendarType (self) |
bool, int (jd) | dateToJulianDay (self, int year, int month, int day, ) |
int | day (self, QDate date) |
int | dayOfWeek (self, QDate date) |
int | dayOfYear (self, QDate date) |
QString | dayString (self, QDate pDate, KCalendarSystem.StringFormat format=KCalendarSystem.LongFormat) |
int, int (iLength) | dayStringToInteger (self, QString sNum, ) |
int | daysInMonth (self, QDate date) |
int | daysInWeek (self, QDate date) |
int | daysInYear (self, QDate date) |
QDate | earliestValidDate (self) |
QDate | epoch (self) |
QString | formatDate (self, QDate date, KLocale.DateFormat format=KLocale.LongDate) |
bool | isLeapYear (self, int year) |
bool | isLeapYear (self, QDate date) |
bool | isLunar (self) |
bool | isLunisolar (self) |
bool | isProleptic (self) |
bool | isSolar (self) |
bool | isValid (self, int year, int month, int day) |
bool | isValid (self, QDate date) |
bool, int (year), int (month), int (day) | julianDayToDate (self, int jd, ) |
QDate | latestValidDate (self) |
KLocale | locale (self) |
int | month (self, QDate date) |
QString | monthName (self, int month, int year, KCalendarSystem.MonthNameFormat format=KCalendarSystem.LongName) |
QString | monthName (self, QDate date, KCalendarSystem.MonthNameFormat format=KCalendarSystem.LongName) |
QString | monthString (self, QDate pDate, KCalendarSystem.StringFormat format=KCalendarSystem.LongFormat) |
int, int (iLength) | monthStringToInteger (self, QString sNum, ) |
int | monthsInYear (self, QDate date) |
QDate, bool (ok) | readDate (self, QString str, ) |
QDate, bool (ok) | readDate (self, QString intstr, QString format, ) |
QDate, bool (ok) | readDate (self, QString str, KLocale.ReadDateFlags flags, ) |
bool | setDate (self, QDate date, int year, int month, int day) |
bool | setYMD (self, QDate date, int y, int m, int d) |
QString | weekDayName (self, int weekDay, KCalendarSystem.WeekDayNameFormat format=KCalendarSystem.LongDayName) |
QString | weekDayName (self, QDate date, KCalendarSystem.WeekDayNameFormat format=KCalendarSystem.LongDayName) |
int | weekDayOfPray (self) |
int, int (yearNum) | weekNumber (self, QDate date, int yearNum=0) |
int | weekStartDay (self) |
int | weeksInYear (self, QDate date) |
int | weeksInYear (self, int year) |
int | year (self, QDate date) |
QString | yearString (self, QDate date, KCalendarSystem.StringFormat format=KCalendarSystem.LongFormat) |
int, int (iLength) | yearStringToInteger (self, QString sNum, ) |
Static Methods | |
QString | calendarLabel (QString calendarType) |
QStringList | calendarSystems () |
KCalendarSystem | create (QString calType=QLatin1String("gregorian"), KLocale locale=0) |
Method Documentation
__init__ | ( | self, | ||
KLocale | locale=0 | |||
) |
Constructor of abstract calendar class. This will be called by derived classes.
- Parameters:
-
locale locale to use for translations. The global locale is used if null.
__init__ | ( | self, | ||
KCalendarSystem | a0 | |||
) |
Returns a QDate containing a date ndays days later.
- Parameters:
-
date The old date ndays number of days to add
- Returns:
- The new date, null date if any errors
Returns a QDate containing a date nmonths months later.
- Parameters:
-
date The old date nmonths number of months to add
- Returns:
- The new date, null date if any errors
Returns a QDate containing a date nyears years later.
- Parameters:
-
date The old date nyears The number of years to add
- Returns:
- The new date, null date if any errors
Returns a typographically correct and translated label to display for the calendar system type. Use with calendarSystems() to neatly format labels to display on combo widget of available calendar systems.
- Parameters:
-
calendarType the specific calendar type to return the label for
- Returns:
- label for calendar
QStringList calendarSystems | ( | ) |
Gets a list of names of supported calendar systems.
- Returns:
- list of names
QString calendarType | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Returns the calendar system type.
- Returns:
- type of calendar system
KCalendarSystem create | ( | QString | calType=QLatin1String("gregorian"), | |
KLocale | locale=0 | |||
) |
Creates specific calendar type
- Parameters:
-
calType string identification of the specific calendar type to be constructed locale locale to use for translations. The global locale is used if null.
- Returns:
- a KCalendarSystem object
bool, int (jd) dateToJulianDay | ( | self, | ||
int | year, | |||
int | month, | |||
int | day, | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Internal method to convert YMD values for this calendar system into a Julian Day number.
All calendar system implementations MUST implement julianDayToDate and dateToJulianDay methods as all other methods can be expressed as functions of these. Does no internal validity checking.
- See also:
- KCalendarSystem.julianDayToDate
- Parameters:
-
year year number month month number day day of month jd Julian day number returned in this variable
- Returns:
- true if the date is valid, false otherwise
int day | ( | self, | ||
QDate | date | |||
) |
Returns the day portion of a given date in the current calendar system
- Parameters:
-
date date to return day for
- Returns:
- day of the month, 0 if input date is invalid
int dayOfWeek | ( | self, | ||
QDate | date | |||
) |
Returns the weekday number for the given date
- Parameters:
-
date the date to obtain day from
- Returns:
- day of week number, -1 if input date not valid
int dayOfYear | ( | self, | ||
QDate | date | |||
) |
Returns the day number of year for the given date
- Parameters:
-
date the date to obtain day from
- Returns:
- day of year number, -1 if input date not valid
QString dayString | ( | self, | ||
QDate | pDate, | |||
KCalendarSystem.StringFormat | format=KCalendarSystem.LongFormat | |||
) |
Converts a date into a day literal
- Parameters:
-
pDate The date to convert format The format to return, either short or long
- Returns:
- The day literal of the date, empty string if any error
int, int (iLength) dayStringToInteger | ( | self, | ||
QString | sNum, | |||
) |
Converts a day literal of a part of a string into a integer starting at the beginning of the string
- Parameters:
-
sNum The string to parse iLength The number of QChars used, and 0 if no valid symbols was found in the string
- Returns:
- An integer corresponding to the day
int daysInMonth | ( | self, | ||
QDate | date | |||
) |
Returns the number of days in the given month.
- Parameters:
-
date the date to obtain month from
- Returns:
- number of days in month, -1 if input date invalid
int daysInWeek | ( | self, | ||
QDate | date | |||
) |
Returns the number of days in the given week.
- Parameters:
-
date the date to obtain week from
- Returns:
- number of days in week, -1 if input date invalid
int daysInYear | ( | self, | ||
QDate | date | |||
) |
Returns the number of days in the given year.
- Parameters:
-
date the date to obtain year from
- Returns:
- number of days in year, -1 if input date invalid
QDate earliestValidDate | ( | self ) |
Returns the earliest date valid in this calendar system implementation.
If the calendar system is proleptic then this may be before epoch.
- See also:
- KCalendarSystem.epoch
- See also:
- KCalendarSystem.latestValidDate
- Returns:
- date the earliest valid date
QDate epoch | ( | self ) |
Returns a QDate holding the epoch of the calendar system. Usually YMD of 1/1/1, access the returned QDates method toJulianDay() if you require the actual Julian day number. Note: a particular calendar system implementation may not include the epoch in its supported range, or the calendar system may be proleptic in which case it supports dates before the epoch.
- See also:
- KCalendarSystem.earliestValidDate
- See also:
- KCalendarSystem.latestValidDate
- See also:
- KCalendarSystem.isProleptic
- See also:
- KCalendarSystem.isValid
- Returns:
- epoch of calendar system
Returns a string formatted to the current locale's conventions regarding dates.
Uses the calendar system's internal locale set when the instance was created, which ensures that the correct calendar system and locale settings are respected, which would not occur in some cases if using the global locale. Defaults to global locale.
- See also:
- KLocale.formatDate
- Parameters:
-
date the date to be formatted format category of date format to use
- Returns:
- The date as a string
bool isLeapYear | ( | self, | ||
int | year | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Returns whether a given year is a leap year.
Input year must be checked for validity in current Calendar System prior to calling, no validity checking performed in this routine, behaviour is undefined in invalid case.
- Parameters:
-
year the year to check
- Returns:
- true if the year is a leap year, false otherwise
bool isLeapYear | ( | self, | ||
QDate | date | |||
) |
Returns whether a given date falls in a leap year.
Input date must be checked for validity in current Calendar System prior to calling, no validity checking performed in this routine, behaviour is undefined in invalid case.
- Parameters:
-
date the date to check
- Returns:
- true if the date falls in a leap year, false otherwise
bool isLunar | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Returns whether the calendar is lunar based.
- Returns:
- true if the calendar is lunar based, false if not
bool isLunisolar | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Returns whether the calendar is lunisolar based.
- Returns:
- true if the calendar is lunisolar based, false if not
bool isProleptic | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Returns whether the calendar system is proleptic, i.e. whether dates before the epoch are supported.
- See also:
- KCalendarSystem.epoch
- Returns:
- true if the calendar system is proleptic, false if not
bool isSolar | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Returns whether the calendar is solar based.
- Returns:
- true if the calendar is solar based, false if not
bool isValid | ( | self, | ||
int | year, | |||
int | month, | |||
int | day | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Returns whether a given date is valid in this calendar system.
- Parameters:
-
year the year portion of the date to check month the month portion of the date to check day the day portion of the date to check
- Returns:
- true if the date is valid, false otherwise
bool isValid | ( | self, | ||
QDate | date | |||
) |
Returns whether a given date is valid in this calendar system.
- Parameters:
-
date the date to check
- Returns:
- true if the date is valid, false otherwise
bool, int (year), int (month), int (day) julianDayToDate | ( | self, | ||
int | jd, | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Internal method to convert a Julian Day number into the YMD values for this calendar system.
All calendar system implementations MUST implement julianDayToDate and dateToJulianDay methods as all other methods can be expressed as functions of these. Does no internal validity checking.
- See also:
- KCalendarSystem.dateToJulianDay
- Parameters:
-
jd Julian day number to convert to date year year number returned in this variable month month number returned in this variable day day of month returned in this variable
- Returns:
- true if the date is valid, false otherwise
QDate latestValidDate | ( | self ) |
Returns the latest date valid in this calendar system implementation.
- See also:
- KCalendarSystem.epoch
- See also:
- KCalendarSystem.earliestValidDate
- Returns:
- date the latest valid date
KLocale locale | ( | self ) |
Returns the locale used for translations and formats for this calendar system instance. This allows a calendar system instance to be independent of the global translations and formats if required. All implementations must refer to this locale.
Only for internal calendar system use; if public access is required then provide public methods only for those methods actually required. Any app that creates an instance with its own locale overriding global will have the original handle to the locale and can manipulate it that way if required, e.g. to change default date format. Only expose those methods that library widgets require access to internally.
- See also:
- KCalendarSystem.formatDate
- See also:
- KLocale.formatDate
- See also:
- KCalendarSystem.weekStartDay
- See also:
- KLocale.weekStartDay
- See also:
- KCalendarSystem.readDate
- See also:
- KLoacle.readDate
- Returns:
- locale to use
int month | ( | self, | ||
QDate | date | |||
) |
Returns the month portion of a given date in the current calendar system
- Parameters:
-
date date to return month for
- Returns:
- month of year, 0 if input date is invalid
QString monthName | ( | self, | ||
int | month, | |||
int | year, | |||
KCalendarSystem.MonthNameFormat | format=KCalendarSystem.LongName | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Gets specific calendar type month name for a given month number If an invalid month is specified, QString() is returned.
- Parameters:
-
month the month number year the year the month belongs to format specifies whether the short month name or long month name should be used
- Returns:
- name of the month, empty string if any error
QString monthName | ( | self, | ||
QDate | date, | |||
KCalendarSystem.MonthNameFormat | format=KCalendarSystem.LongName | |||
) |
Gets specific calendar type month name for a given date
- Parameters:
-
date date to obtain month from format specifies whether the short month name or long month name should be used
- Returns:
- name of the month, empty string if any error
QString monthString | ( | self, | ||
QDate | pDate, | |||
KCalendarSystem.StringFormat | format=KCalendarSystem.LongFormat | |||
) |
Converts a date into a month literal
- Parameters:
-
pDate The date to convert format The format to return, either short or long
- Returns:
- The month literal of the date, empty string if any error
int, int (iLength) monthStringToInteger | ( | self, | ||
QString | sNum, | |||
) |
Converts a month literal of a part of a string into a integer starting at the beginning of the string
- Parameters:
-
sNum The string to parse iLength The number of QChars used, and 0 if no valid symbols was found in the string
- Returns:
- An integer corresponding to the month
int monthsInYear | ( | self, | ||
QDate | date | |||
) |
Returns number of months in the given year
- Parameters:
-
date the date to obtain year from
- Returns:
- number of months in the year, -1 if input date invalid
Converts a localized date string to a QDate. The bool pointed by ok will be false if the date entered was invalid.
Uses the calendar system's internal locale set when the instance was created, which ensures that the correct calendar system and locale settings are respected, which would not occur in some cases if using the global locale. Defaults to global locale.
- See also:
- KLocale.readDate
- Parameters:
-
str the string to convert ok if non-null, will be set to true if the date is valid, false if invalid
- Returns:
- the string converted to a QDate
Converts a localized date string to a QDate, using the specified format. You will usually not want to use this method.
- See also:
- KLocale.readDate
Converts a localized date string to a QDate. This method is stricter than readDate(str,&ok): it will either accept a date in full format or a date in short format, depending on flags.
Uses the calendar system's internal locale set when the instance was created, which ensures that the correct calendar system and locale settings are respected, which would not occur in some cases if using the global locale. Defaults to global locale.
- See also:
- KLocale.readDate
- Parameters:
-
str the string to convert flags whether the date string is to be in full format or in short format ok if non-null, will be set to true if the date is valid, false if invalid
- Returns:
- the string converted to a QDate
bool setDate | ( | self, | ||
QDate | date, | |||
int | year, | |||
int | month, | |||
int | day | |||
) |
Changes the date's year, month and day. The range of the year, month and day depends on which calendar is being used. All years entered are treated literally, i.e. no Y2K translation is applied to years entered in the range 00 to 99. Replaces setYMD.
- Parameters:
-
date date to change year year month month number day day of month
- Returns:
- true if the date is valid, false otherwise
bool setYMD | ( | self, | ||
QDate | date, | |||
int | y, | |||
int | m, | |||
int | d | |||
) |
- Deprecated:
Use setDate instead
- See also:
- KCalendarSystem.setDate
Some implementations reject year range 00 to 99, but extended date ranges now require these to be accepted. Equivalent in QDate is obsoleted.
Changes the date's year, month and day. The range of the year, month and day depends on which calendar is being used.
- Parameters:
-
date Date to change y Year m Month number d Day of month
- Returns:
- true if the date is valid; otherwise returns false.
QString weekDayName | ( | self, | ||
int | weekDay, | |||
KCalendarSystem.WeekDayNameFormat | format=KCalendarSystem.LongDayName | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Gets specific calendar type week day name. If an invalid week day is specified, QString() is returned.
- Parameters:
-
weekDay number of day in week (Monday = 1, ..., Sunday = 7) format specifies whether the short month name or long month name should be used
- Returns:
- day name, empty string if any error
QString weekDayName | ( | self, | ||
QDate | date, | |||
KCalendarSystem.WeekDayNameFormat | format=KCalendarSystem.LongDayName | |||
) |
Gets specific calendar type week day name.
- Parameters:
-
date the date format specifies whether the short month name or long month name should be used
- Returns:
- day name, empty string if any error
int weekDayOfPray | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Returns the day of the week traditionally associated with religious observance for this calendar system. Note this may not be accurate for the users locale, e.g. Gregorian calendar used in non-Christian countries, in use cases where this could be an issue it is recommended to use KLocale.weekDayOfPray() instead.
- Returns:
- day number (None = 0, Monday = 1, ..., Sunday = 7)
int, int (yearNum) weekNumber | ( | self, | ||
QDate | date, | |||
int | yearNum=0 | |||
) |
Returns the ISO week number for the given date.
ISO 8601 defines the first week of the year as the week containing the first Thursday. See http://en.wikipedia.org/wiki/ISO_8601 and http://en.wikipedia.org/wiki/ISO_week_date
If the date falls in the last week of the previous year or the first week of the following year, then the yearNum returned will be set to the appropriate year.
- Parameters:
-
date the date to obtain week from yearNum returns the year the date belongs to
- Returns:
- ISO week number, -1 if input date invalid
int weekStartDay | ( | self ) |
Use this to determine which day is the first day of the week.
Uses the calendar system's internal locale set when the instance was created, which ensures that the correct calendar system and locale settings are respected, which would not occur in some cases if using the global locale. Defaults to global locale.
- See also:
- KLocale.weekStartDay
- Returns:
- an integer (Monday = 1, ..., Sunday = 7)
int weeksInYear | ( | self, | ||
QDate | date | |||
) |
Returns the number of ISO weeks in the given year.
- Parameters:
-
date the date to obtain year from
- Returns:
- number of weeks in the year, -1 if input date invalid
int weeksInYear | ( | self, | ||
int | year | |||
) |
Returns the number of ISO weeks in the given year.
ISO 8601 defines the first week of the year as the week containing the first Thursday. See http://en.wikipedia.org/wiki/ISO_8601 and http://en.wikipedia.org/wiki/ISO_week_date
- Parameters:
-
year the year
- Returns:
- number of weeks in the year, -1 if input date invalid
int year | ( | self, | ||
QDate | date | |||
) |
Returns the year portion of a given date in the current calendar system
- Parameters:
-
date date to return year for
- Returns:
- year, 0 if input date is invalid
QString yearString | ( | self, | ||
QDate | date, | |||
KCalendarSystem.StringFormat | format=KCalendarSystem.LongFormat | |||
) |
Converts a date into a year literal
- Parameters:
-
date date to convert format format to return, either short or long
- Returns:
- year literal of the date, empty string if any error
int, int (iLength) yearStringToInteger | ( | self, | ||
QString | sNum, | |||
) |
Converts a year literal of a part of a string into a integer starting at the beginning of the string
- Parameters:
-
sNum The string to parse iLength The number of QChars used, and 0 if no valid symbols was found in the string
- Returns:
- An integer corresponding to the year
Enumeration Documentation
MonthNameFormat |
Format for returned month / day name.
- Enumerator:
-
ShortName LongName ShortNamePossessive LongNamePossessive
StringFormat |
Format for returned year number / month number / day number as string.
- Enumerator:
-
ShortFormat LongFormat
WeekDayNameFormat |
Format for returned month / day name.
- Enumerator:
-
ShortDayName LongDayName