/usr/include/klocalizeddate.h is in kdelibs5-dev 4:4.14.2-5+deb8u2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 | /*
Copyright 2010 John Layt <john@layt.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KLOCALIZEDDATE_H
#define KLOCALIZEDDATE_H
#include <QtCore/QString>
#include <QtCore/QDate>
#include <kdecore_export.h>
#include "kcalendarsystem.h"
#include "klocale.h"
class KLocalizedDatePrivate;
/**
* @short A class representing a date localized using the local calendar system, language and formats
*
* Topics:
* - @ref intro
* - @ref calsys
* - @ref custom
* - @ref formatting
* - @ref maths
*
* @section intro Introduction
*
* This class provides a simple and convenient way to localize dates
*
* @section calsys Calendar System
*
* KDE supports the use of different calendar systems.
*
* @section custom Default and Custom Locale and Calendar System
*
* In most cases you will want to use the default Global Locale and Calendar
* System, in which case you need only create a default KLocalizedDate. If
* however you specifically need a different Calendar System or Locale settings
* then you need to take some extra steps.
*
* The simplest method is just changing the Calendar System while keeping the
* current Locale settings. This is easily done using setCalendarSystem()
* which will copy the current Locale being used and apply this to the new
* Calendar System. Note this means any changes to the old locale settings,
* either the Global Locale or a custom Locale (see below) will not apply
* to that date instance.
*
* You may however wish to use a custom Locale with the Calendar System.
* For example, if you want your app to normally show dates using the Global
* Locale and Calendar System, but wish to show an info box with the Islamic
* date in Arabic language and format, then you need a custom Locale to do
* this.
*
* \code
* KLocale *myLocale = new KLocale("myapp", "ar", "eg");
* KCalendarSystem *myCalendar = KCalendarSystem::create(KLocale::IslamicCivilCalendar, myLocale);
* KLocalizedDate myDate(QDate(2010,1,1), myCalendar);
* \endcode
*
* In this case you are responsible for the memory management of the KLocale
* and KCalendarSystem. This allows you to reuse this calendar across multiple
* date instances without it being deleted under you. It also allows you to
* change any setting in the Locale and have it apply across all those date
* instances. @warning Don't try changing the Calendar System via your Locale
* instance, your KCalendarSystem instance will be deleted and all the dates
* will be invalid!
*
* @see
*
* @section formatting Date Formatting
*
* When you display dates or date components to users in a GUI, they will
* expect them to be displayed in their language and digit set following their
* local date formatting conventions. Directly displaying values returned by
* the normal date component methods such as day() will not conform to these
* expectations, so you need to use different methods to obtain the localized
* string form of the date or component.
*
* You can either format the entire date, or just a single component of the
* date such as the month or day.
*
* When formatting a full date, it is preferred to use one of the standard date
* formats defined in the Locale, although you can provide your own format in
* either the KDE, POSIX, or UNICODE standards.
*
* @see formatDate() formatDate()
*
* @section parsing Date Parsing
*
* Basic concepts on date parsing, then full details on KLocale::ReadDateFlags
* formats, definging your own date format strings, and setting how strictly
* the format is appplied.
*
* You can choose how strictly a date format is applied in parsing. Currently
* only liberal Parsing is supported.
*
* The KLocale::LiberalParsing mode applies the following rules:
*
* 1) You must supply a format and string containing at least one of the following combinations to
* create a valid date:
* @li a month and day of month
* @li a day of year
* @li a ISO week number and day of week
*
* 2) If a year number is not supplied then the current year will be assumed.
*
* 3) All date components must be separated by a non-numeric character.
*
* 4) The format is not applied strictly to the input string:
* @li extra whitespace is ignored
* @li leading 0's on numbers are ignored
* @li capitalisation of literals is ignored
*
* @see readDate()
*
* @section maths Date Maths
*
* A full set of date maths functions are provided which operate in a consistent
* manner, i.e. you can safely round-trip.
*
*/
class KDECORE_EXPORT KLocalizedDate
{
public:
/**
* Constructs a localized date with the given date.
*
* By default, uses the global Calendar System and Locale.
*
* If you pass in a custom Calendar System then you retain ownership of it
* and are responsible for deleting it. This allows you to reuse the same
* custom Calendar System for many localized date instances.
*
* See @ref custom for more details on using custom Calendar Systems.
*
* @param date the QDate to set the KLocalizedDate to, defaults to invalid date
* @param calendar the calendar system to use, defaults to the global
*/
explicit KLocalizedDate(const QDate &date = QDate(), const KCalendarSystem *calendar = 0);
/**
* Constructs a localized date with the given year, month and day.
*
* By default, uses the global Calendar System and Locale.
*
* If you pass in a custom Calendar System then you retain ownership of it
* and are responsible for deleting it. This allows you to reuse the same
* custom Calendar System for many localized date instances.
*
* See @ref custom for more details on using custom Calendar Systems.
*
* @param year the year to set the KLocalizedDate to
* @param month the month to set the KLocalizedDate to
* @param day the day to set the KLocalizedDate to
* @param calendar the calendar system to use, defaults to the global
*/
KLocalizedDate(int year, int month, int day, const KCalendarSystem *calendar = 0);
/**
* Copy constructor
*
* @param rhs the date to copy
*/
KLocalizedDate(const KLocalizedDate &rhs);
/**
* Assignment operator
*
* @param rhs the date to assign
*/
KLocalizedDate &operator=(const KLocalizedDate &rhs);
/**
* Assignment operator
*
* @param rhs the date to assign
*/
KLocalizedDate &operator=(const QDate &rhs);
/**
* Destructor.
*/
~KLocalizedDate();
/**
* Set the Calendar System used for this date instance only.
*
* This method is mostly useful for when you quickly want to see what the
* currently set date would look like in a different Calendar System but
* using the same Locale.
*
* When the Calendar System is changed, a copy will be taken of the Locale
* previously used and this copy will be applied to the new Calendar System.
* Any changes to the old Locale settings, either the Global or a Custom
* Locale, will not be applied to this date instance.
*
* See @ref custom for more details on using custom Calendar Systems.
*
* @see KLocale::CalendarSystem
* @see calendarSystem()
* @param calendarSystem the Calendar System to use
*/
void setCalendarSystem(KLocale::CalendarSystem calendarSystem);
/**
* Returns the Calendar System used by this localized date instance
*
* @see KLocale::CalendarSystem
* @see setCalendarSystem()
* @return the Calendar System currently used
*/
KLocale::CalendarSystem calendarSystem();
/**
* Returns a pointer to the Calendar System object used by this date instance.
*
* Usually this will be the Global Calendar System, but this may have been
* changed.
*
* Normally you will not need to access this object unless the KLocalizedDate
* API does not provide the methods you require.
*
* @see KCalendarSystem
* @see calendarSystem
* @see setCalendarSystem
* @return the current calendar system instance
*/
const KCalendarSystem *calendar() const;
/**
* Returns whether the date is null, i.e. invalid in any Calendar System.
*
* @see isValid
* @return @c true if the date is null, @c false otherwise
*/
bool isNull() const;
/**
* Returns whether the date is valid in the current Calendar System.
*
* @see isNull
* @return @c true if the date is valid, @c false otherwise
*/
bool isValid() const;
/**
* Set the date using a QDate.
*
* @param date the QDate to set to
* @return @c true if the date is valid, @c false otherwise
*/
bool setDate(const QDate &date);
/**
* Set the date's year, month and day.
*
* The range of the year, month and day, and the validity of the date as a
* whole depends on which Calendar System is being used.
*
* @see getDate()
* @param year year number
* @param month month of year number
* @param day day of month
* @return @c true if the date is valid, @c false otherwise
*/
bool setDate(int year, int month, int day);
/**
* Set the date using the year number and day of year number only.
*
* @see dayOfYear()
* @param year year
* @param dayOfYear day of year
* @return @c true if the date is valid, @c false otherwise
*/
bool setDate(int year, int dayOfYear);
/**
* Set the date using the era, year in era number, month and day
*
* @see eraName()
* @see yearInEra()
* @param eraName Era string
* @param yearInEra Year In Era number
* @param month Month number
* @param day Day Of Month number
* @return @c true if the date is valid, @c false otherwise
*/
bool setDate(QString eraName, int yearInEra, int month, int day);
/**
* Set the date using the year, week and day of week.
*
* Currently only the ISO Week Number System is supported.
*
* @see week()
* @see dayOfWeek()
* @param weekNumberSystem the week number system to use
* @param year year
* @param weekOfYear week of year
* @param dayOfWeek day of week Mon..Sun (1..7)
* @return @c true if the date is valid, @c false otherwise
*/
bool setDate(KLocale::WeekNumberSystem weekNumberSystem, int year, int weekOfYear, int dayOfWeek);
/**
* Set the date to today's date
*
* @see currentDate()
* @return @c true if the date is valid, @c false otherwise
*/
bool setCurrentDate();
/**
* Returns a KLocalizedDate set to today's date in the Global Locale and
* Calendar System.
*
* @see setCurrentDate()
* @return today's localized date
*/
static KLocalizedDate currentDate();
/**
* Returns a KLocalizedDate set the required date in the Global Locale and
* Calendar System.
*
* @param date the date to set to
* @return a localized date
*/
static KLocalizedDate fromDate(const QDate &date);
/**
* Returns a KLocalizedDate set the required Julian Day number in the Global
* Locale and Calendar System.
*
* @see toJulianDay()
* @param jd the Julian Day number to set to
* @return a localized date
*/
static KLocalizedDate fromJulianDay(int jd);
/**
* Returns the currently set date as a Julian Day number
*
* @see fromJulianDay()
* @return the currently set date as a Julian Day number
*/
int toJulianDay() const;
/**
* Returns the currently set date as a QDate
*
* @return the currently set date as a QDate
*/
QDate date() const;
/**
* Returns the year, month and day portion of the date in the current
* Calendar System.
*
* See @ref formatting for why you should never display this value.
*
* @see setDate()
* @see formatDate()
* @param year year number returned in this variable
* @param month month number returned in this variable
* @param day day of month returned in this variable
*/
void getDate(int *year, int *month, int *day) const;
/**
* Returns the year portion of the date in the current calendar system
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return the localized year number
*/
int year() const;
/**
* Returns the month portion of the date in the current calendar system
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return the localized month number, 0 if date is invalid
*/
int month() const;
/**
* Returns the day portion of the date in the current calendar system
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return the localized day number, 0 if date is invalid
*/
int day() const;
/**
* Returns the Era Name portion of the date in the current calendar system,
* for example "AD" or "Anno Domini" for the Gregorian calendar and Christian Era.
*
* See @ref formatting for more details on Date Formatting.
*
* @see formatDate()
* @return the localized era name, empty string if date is invalid
*/
QString eraName() const;
/**
* Returns the Era Year portion of the date in the current
* calendar system, for example "2000 AD" or "Heisei 22".
*
* See @ref formatting for more details on Date Formatting.
*
* @see formatDate()
* @return the localized era year string, empty string if date is invalid
*/
QString eraYear() const;
/**
* Returns the Year In Era portion of the date in the current calendar
* system, for example 1 for "1 BC".
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @see formatYearInEra()
* @return the localized Year In Era number, -1 if date is invalid
*/
int yearInEra() const;
/**
* Returns the day number of year for the date
*
* The days are numbered 1..daysInYear()
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return day of year number, -1 if date not valid
*/
int dayOfYear() const;
/**
* Returns the weekday number for the date
*
* The weekdays are numbered 1..7 for Monday..Sunday.
*
* This value is @em not affected by the value of KLocale::weekStartDay()
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return day of week number, -1 if date not valid
*/
int dayOfWeek() const;
/**
* Returns the localized Week Number for the date.
*
* See @ref formatting for why you should never display this value.
*
* This may be ISO, US, or any other supported week numbering scheme. If
* you specifically require the ISO Week or any other scheme, you should use
* the week(KLocale::WeekNumberSystem) form.
*
* 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.
*
* @see weeksInYear()
* @see formatDate()
* @param yearNum returns the year the date belongs to
* @return localized week number, -1 if input date invalid
*/
int week(int *yearNum = 0) const;
/**
* Returns the Week Number for the date in the required Week Number System.
*
* See @ref formatting for why you should never display this value.
*
* Unless you want a specific Week Number System (e.g. ISO Week), you should
* use the localized Week Number form of week().
*
* 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.
*
* Technically, the ISO Week Number only applies to the ISO/Gregorian Calendar
* System, but the same rules will be applied to the current Calendar System.
*
* @see weeksInYear()
* @see formatDate()
* @param weekNumberSystem the Week Number System to use
* @param yearNum returns the year the date belongs to
* @return week number, -1 if input date invalid
*/
int week(KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const;
/**
* Returns number of months in the year
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return number of months in the year, -1 if date invalid
*/
int monthsInYear() const;
/**
* Returns the number of localized weeks in the currently set year.
*
* See @ref formatting for why you should never display this value.
*
* If you specifically require the number of ISO Weeks, you should use
* weeksInYear(KLocale::IsoWeekNumber)
*
* @see week()
* @see formatDate()
* @return number of weeks in the year, -1 if date invalid
*/
int weeksInYear() const;
/**
* Returns the number of Weeks in the currently set year using the required
* Week Number System.
*
* See @ref formatting for why you should never display this value.
*
* Unless you specifically want a particular Week Number System (e.g. ISO Weeks)
* you should use the localized number of weeks provided by weeksInYear().
*
* @see week()
* @see formatDate()
* @param weekNumberSystem the week number system to use
* @return number of weeks in the year, -1 if date invalid
*/
int weeksInYear(KLocale::WeekNumberSystem weekNumberSystem) const;
/**
* Returns the number of days in the year.
*
* For example, in the Gregorian calendar most years have 365 days but Leap
* Years have 366 years. Other Calendar Systems have different length years.
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return number of days in year, -1 if date invalid
*/
int daysInYear() const;
/**
* Returns the number of days in the month.
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return number of days in month, -1 if date invalid
*/
int daysInMonth() const;
/**
* Returns the number of days in the week.
*
* See @ref formatting for why you should never display this value.
*
* @see formatDate()
* @return number of days in week, -1 if date invalid
*/
int daysInWeek() const;
/**
* Returns whether the currently set date falls in a Leap Year in the
* current Calendar System.
*
* @return true if the date falls in a leap year
*/
bool isLeapYear() const;
/**
* Returns the Date as a localized string in the requested standard Locale
* format.
*
* See @ref formatting for more details on Date Formatting and valid Locale
* formats.
*
* @see formatDate()
* @param dateFormat the standard date format to use
* @return The date as a localized string
*/
QString formatDate(KLocale::DateFormat dateFormat = KLocale::LongDate) const;
/**
* Returns the Date as a localized string in the requested format.
*
* See @ref formatting for more details on Date Formatting and valid format
* codes.
*
* Please use with care and only in situations where the standard Locale
* formats or the component format methods do not provide what you
* need. You should almost always translate your @p formatString as
* documented above. Using the standard DateFormat options instead would
* take care of the translation for you.
*
* The toFormat parameter is a good candidate to be made translatable,
* so that translators can adapt it to their language's convention.
* There should also be a context using the "kdedt-format" keyword (for
* automatic validation of translations) and stating the format's purpose:
* \code
* QDate reportDate;
* KGlobal::locale()->calendar()->setDate(reportDate, reportYear, reportMonth, 1);
* dateFormat = i18nc("(kdedt-format) Report month and year in report header", "%B %Y"));
* dateString = KGlobal::locale()->calendar()->formatDate(reportDate, dateFormat);
* \endcode
*
* The date format string can be defined using either the KDE, POSIX or the Qt
* subset of the UNICODE standards.
*
* The KDE standard closely follows the POSIX standard but with some exceptions.
* Always use the KDE standard within KDE, but where interaction is required with
* external POSIX compliant systems (e.g. Gnome, glibc, etc) the POSIX standard
* should be used. The UNICODE standard is provided for comaptability with QDate
* and so is not yet the full standard, only what Qt currently supports.
*
* Date format strings are made up of date components and string literals.
* Date components are prefixed by a % escape character and are made up of
* optional padding and case modifier flags, an optional width value, and a
* compulsary code for the actual date component:
* %[Flags][Width][Componant]
* e.g. %_^5Y
* No spaces are allowed.
*
* The Flags can modify the padding character and/or case of the Date Componant.
* The Flags are optional and may be combined and/or repeated in any order,
* in which case the last Padding Flag and last Case Flag will be the
* ones used. The Flags must be immediately after the % and before any Width.
*
* The Width can modify how wide the date Componant is padded to. The Width
* is an optional interger value and must be after any Flags but before the
* Componant. If the Width is less than the minimum defined for a Componant
* then the default minimum will be used instead.
*
* By default most numeric Date Componants are right-aligned with leading 0's.
*
* By default all string name fields are capital case and unpadded.
*
* The following Flags may be specified:
* @li - (hyphen) no padding (e.g. 1 Jan and "%-j" = "1")
* @li _ (underscore) pad with spaces (e.g. 1 Jan and "%-j" = " 1")
* @li 0 (zero) pad with 0's (e.g. 1 Jan and "%0j" = "001")
* @li ^ (caret) make uppercase (e.g. 1 Jan and "%^B" = "JANUARY")
* @li # (hash) invert case (e.g. 1 Jan and "%#B" = "???")
*
* The following Date Componants can be specified:
* @li %Y the year to 4 digits (e.g. "1984" for 1984, "0584" for 584, "0084" for 84)
* @li %C the 'century' portion of the year to 2 digits (e.g. "19" for 1984, "05" for 584, "00" for 84)
* @li %y the lower 2 digits of the year to 2 digits (e.g. "84" for 1984, "05" for 2005)
* @li %EY the full local era year (e.g. "2000 AD")
* @li %EC the era name short form (e.g. "AD")
* @li %Ey the year in era to 1 digit (e.g. 1 or 2000)
* @li %m the month number to 2 digits (January="01", December="12")
* @li %n the month number to 1 digit (January="1", December="12"), see notes!
* @li %d the day number of the month to 2 digits (e.g. "01" on the first of March)
* @li %e the day number of the month to 1 digit (e.g. "1" on the first of March)
* @li %B the month name long form (e.g. "January")
* @li %b the month name short form (e.g. "Jan" for January)
* @li %h the month name short form (e.g. "Jan" for January)
* @li %A the weekday name long form (e.g. "Wednesday" for Wednesday)
* @li %a the weekday name short form (e.g. "Wed" for Wednesday)
* @li %j the day of the year number to 3 digits (e.g. "001" for 1 Jan)
* @li %V the ISO week of the year number to 2 digits (e.g. "01" for ISO Week 1)
* @li %G the year number in long form of the ISO week of the year to 4 digits (e.g. "2004" for 1 Jan 2005)
* @li %g the year number in short form of the ISO week of the year to 2 digits (e.g. "04" for 1 Jan 2005)
* @li %u the day of the week number to 1 digit (e.g. "1" for Monday)
* @li %D the US short date format (e.g. "%m/%d/%y")
* @li %F the ISO short date format (e.g. "%Y-%m-%d")
* @li %x the KDE locale short date format
* @li %% the literal "%"
* @li %t a tab character
*
* Everything else in the format string will be taken as literal text.
*
* Examples:
* "%Y-%m-%d" = "2009-01-01"
* "%Y-%-m-%_4d" = "2009-1- 1"
*
* The following format codes behave differently in the KDE and POSIX standards
* @li %e in GNU/POSIX is space padded to 2 digits, in KDE is not padded
* @li %n in GNU/POSIX is newline, in KDE is short month number
*
* The following POSIX format codes are currently not supported:
* @li %U US week number
* @li %w US day of week
* @li %W US week number
* @li %O locale's alternative numeric symbols, in KDE is not supported
*
* %0 is not supported as the returned result is always in the locale's chosen numeric symbol digit set.
*
* @see formatDate()
* @param formatString the date format to use
* @param formatStandard the standard the @p dateFormat uses, defaults to KDE Standard
* @return The date as a localized string
*/
QString formatDate(const QString &formatString,
KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const;
/**
* Returns a Date Component as a localized string in the requested format.
*
* See @ref formatting for more details on Date Formatting.
*
* Each format size may vary depending on Locale and Calendar System but will
* generally match the format description. Some formats may not be directly
* valid but a sensible value will always be returned.
*
* For example for 2010-01-01 the KLocale::Month with en_US Locale and Gregorian calendar may return:
* KLocale::ShortNumber = "1"
* KLocale::LongNumber = "01"
* KLocale::NarrowName = "J"
* KLocale::ShortName = "Jan"
* KLocale::LongName = "January"
*
* @see formatDate()
* @param component The date component to return
* @param format The format to return the @p component in
* @param weekNumberSystem To override the default Week Number System to use
* @return The string form of the date component
*/
QString formatDate(KLocale::DateTimeComponent component,
KLocale::DateTimeComponentFormat format = KLocale::DefaultComponentFormat,
KLocale::WeekNumberSystem weekNumberSystem = KLocale::DefaultWeekNumber) const;
/**
* Converts a localized date string to a KLocalizedDate using either the
* Global Calendar System and Locale, or the provided Calendar System.
*
* See @ref parsing for more details on Date Parsing from strings.
*
* This method is more liberal and will return a valid date if the
* @p dateString matches any of the KLocale::ReadDateFlags formats
* for the Locale.
*
* If you require a certain KLocale::ReadDateFlags format or a customized
* format string, use one of the other readDate() methods.
*
* @param dateString the string to parse
* @param parseMode how strictly to apply the locale formats to the @p dateString
* @param calendar the Calendar System to use when parsing the date
* @return the localized date parsed from the string
*/
static KLocalizedDate readDate(const QString &dateString,
KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing,
const KCalendarSystem *calendar = 0);
/**
* Converts a localized date string to a KLocalizedDate using either the
* Global Calendar System and Locale, or the provided Calendar System.
*
* See @ref parsing for more details on Date Parsing from strings.
*
* This method is stricter and will return a valid date only if the
* @p dateString matches one of the @p dateFlags formats requested.
*
* If you require any KLocale::ReadDateFlags format or a customized format
* string, use one of the other readDate() methods.
*
* @param dateString the string to parse
* @param formatFlags the locale format(s) to try parse the string with
* @param parseMode how strictly to apply the @p formatFlags to the @p dateString
* @param calendar the Calendar System to use when parsing the date
* @return the localized date parsed from the string
*/
static KLocalizedDate readDate(const QString &dateString,
KLocale::ReadDateFlags formatFlags,
KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing,
const KCalendarSystem *calendar = 0);
/**
* Converts a localized date string to a KLocalizedDate using either the
* Global Calendar System and Locale, or the provided Calendar System.
*
* See @ref parsing for more details on Date Parsing from strings.
*
* This method allows you to define your own date format to parse the date
* string with.
*
* If you require one of the standard any KLocale::ReadDateFlags formats
* then use one of the other readDate() methods.
*
* @param dateString the string to parse
* @param dateFormat the date format to try parse the string with
* @param parseMode how strictly to apply the @p dateFormat to the @p dateString
* @param formatStandard the standard the @p dateFormat format uses
* @param calendar the Calendar System to use when parsing the date
* @return the localized date parsed from the string
*/
static KLocalizedDate readDate(const QString &dateString,
const QString &dateFormat,
KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing,
KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat,
const KCalendarSystem *calendar = 0);
/**
* Returns a KLocalizedDate containing a date @p years years later.
*
* @see addYearsTo()
* @see addMonths() addDays()
* @see dateDifference() yearsDifference()
* @param years The number of years to add
* @return The new date, null date if any errors
*/
KLocalizedDate addYears(int years) const;
/**
* Add years onto this date instance.
*
* If the result of the addition is invalid in the current Calendar System
* then the date will become invalid.
*
* @see addYears()
* @see addMonthsTo() addDaysTo()
* @see dateDifference() yearsDifference()
* @param years The number of years to add
* @return if the resulting date is valid
*/
bool addYearsTo(int years);
/**
* Returns a KLocalizedDate containing a date @p months months later.
*
* @see addMonthsTo()
* @see addYears() addDays()
* @see dateDifference() yearsDifference()
* @param months number of months to add
* @return The new date, null date if any errors
*/
KLocalizedDate addMonths(int months) const;
/**
* Add months onto this date instance.
*
* If the result of the addition is invalid in the current Calendar System
* then the date will become invalid.
*
* @see addMonths()
* @see addYearsTo() addDaysTo()
* @see dateDifference() yearsDifference()
* @param months The number of months to add
* @return if the resulting date is valid
*/
bool addMonthsTo(int months);
/**
* Returns a KLocalizedDate containing a date @p days days later.
*
* @see addDaysTo()
* @see addYears() addMonths()
* @see dateDifference() yearsDifference()
* @param days number of days to add
* @return The new date, null date if any errors
*/
KLocalizedDate addDays(int days) const;
/**
* Add days onto this date instance.
*
* If the result of the addition is invalid in the current Calendar System
* then the date will become invalid.
*
* @see addDays()
* @see addYearsTo(), addMonthsTo()
* @see dateDifference() yearsDifference()
* @param days The number of days to add
* @return if the resulting date is valid
*/
bool addDaysTo(int days);
/**
* Returns the difference between this and another date in years, months and days
* in the current Calendar System.
*
* The difference is always calculated from the earlier date to the later
* date in year, month and day order, with the @p direction parameter
* indicating which direction the difference is applied from this date.
* In other words, this difference can be added onto the earlier date in
* year, month, day order to reach the later date.
*
* For example, the difference between 2010-06-10 and 2012-09-5 is 2 years,
* 2 months and 26 days. Note that the difference between two last days of
* the month is always 1 month, e.g. 2010-01-31 to 2010-02-28 is 1 month
* not 28 days.
*
* @see addYears() addMonths() addDays()
* @see yearsDifference() monthsDifference() daysDifference()
* @param toDate The date to end at
* @param yearsDiff Returns number of years difference
* @param monthsDiff Returns number of months difference
* @param daysDiff Returns number of days difference
* @param direction Returns direction of difference, 1 if this Date <= toDate, -1 otherwise
*/
void dateDifference(const KLocalizedDate &toDate,
int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;
/**
* Returns the difference between this and another date in years, months and days
* in the current Calendar System.
*
* The difference is always calculated from the earlier date to the later
* date in year, month and day order, with the @p direction parameter
* indicating which direction the difference is applied from this date.
* In other words, this difference can be added onto the earlier date in
* year, month, day order to reach the later date.
*
* For example, the difference between 2010-06-10 and 2012-09-5 is 2 years,
* 2 months and 26 days. Note that the difference between two last days of
* the month is always 1 month, e.g. 2010-01-31 to 2010-02-28 is 1 month
* not 28 days.
*
* @see addYears() addMonths() addDays()
* @see yearsDifference() monthsDifference() daysDifference()
* @param toDate The date to end at
* @param yearsDiff Returns number of years difference
* @param monthsDiff Returns number of months difference
* @param daysDiff Returns number of days difference
* @param direction Returns direction of difference, 1 if this Date <= toDate, -1 otherwise
*/
void dateDifference(const QDate &toDate,
int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;
/**
* Returns the difference between this and another date in completed calendar years
* in the current Calendar System.
*
* The returned value will be negative if @p toDate < this date.
*
* For example, the difference between 2010-06-10 and 2012-09-5 is 2 years.
*
* @see addYears()
* @see dateDifference() monthsDifference() daysDifference()
* @param toDate The date to end at
* @return The number of years difference
*/
int yearsDifference(const KLocalizedDate &toDate) const;
/**
* Returns the difference between this and another date in completed calendar years
* in the current Calendar System.
*
* The returned value will be negative if @p toDate < this date.
*
* For example, the difference between 2010-06-10 and 2012-09-5 is 2 years.
*
* @see addYears()
* @see dateDifference() monthsDifference() daysDifference()
* @param toDate The date to end at
* @return The number of years difference
*/
int yearsDifference(const QDate &toDate) const;
/**
* Returns the difference between this and another date in completed calendar months
* in the current Calendar System.
*
* The returned value will be negative if @p toDate < this date.
*
* For example, the difference between 2010-06-10 and 2012-09-5 is 26 months.
* Note that the difference between two last days of the month is always 1
* month, e.g. 2010-01-31 to 2010-02-28 is 1 month not 28 days.
*
* @see addMonths()
* @see dateDifference() yearsDifference() daysDifference()
* @param toDate The date to end at
* @return The number of months difference
*/
int monthsDifference(const KLocalizedDate &toDate) const;
/**
* Returns the difference between this and another date in completed calendar months
* in the current Calendar System.
*
* The returned value will be negative if @p toDate < this date.
*
* For example, the difference between 2010-06-10 and 2012-09-5 is 26 months.
* Note that the difference between two last days of the month is always 1
* month, e.g. 2010-01-31 to 2010-02-28 is 1 month not 28 days.
*
* @see addMonths()
* @see dateDifference() yearsDifference() daysDifference()
* @param toDate The date to end at
* @return The number of months difference
*/
int monthsDifference(const QDate &toDate) const;
/**
* Returns the difference between this and another date in days
* The returned value will be negative if @p toDate < this date.
*
* @see addDays()
* @see dateDifference() yearsDifference() monthsDifference()
* @param toDate The date to end at
* @return The number of days difference
*/
int daysDifference(const KLocalizedDate &toDate) const;
/**
* Returns the difference between this and another date in days
* The returned value will be negative if @p toDate < this date.
*
* @see addDays()
* @see dateDifference() yearsDifference() monthsDifference()
* @param toDate The date to end at
* @return The number of days difference
*/
int daysDifference(const QDate &toDate) const;
/**
* Returns a KLocalizedDate containing the first day of the currently set year
*
* @see lastDayOfYear()
* @return The first day of the year
*/
KLocalizedDate firstDayOfYear() const;
/**
* Returns a KLocalizedDate containing the last day of the currently set year
*
* @see firstDayOfYear()
* @return The last day of the year
*/
KLocalizedDate lastDayOfYear() const;
/**
* Returns a KLocalizedDate containing the first day of the currently set month
*
* @see lastDayOfMonth()
* @return The first day of the month
*/
KLocalizedDate firstDayOfMonth() const;
/**
* Returns a KLocalizedDate containing the last day of the currently set month
*
* @see firstDayOfMonth()
* @return The last day of the month
*/
KLocalizedDate lastDayOfMonth() const;
/**
* KLocalizedDate equality operator
*
* @param other the date to compare
*/
bool operator==(const KLocalizedDate &other) const;
/**
* QDate equality operator
*
* @param other the date to compare
*/
bool operator==(const QDate &other) const;
/**
* KLocalizedDate inequality operator
*
* @param other the date to compare
*/
bool operator!=(const KLocalizedDate &other) const;
/**
* QDate inequality operator
*
* @param other the date to compare
*/
bool operator!=(const QDate &other) const;
/**
* KLocalizedDate less than operator
*
* @param other the date to compare
*/
bool operator<(const KLocalizedDate &other) const;
/**
* QDate less than operator
*
* @param other the date to compare
*/
bool operator<(const QDate &other) const;
/**
* KLocalizedDate less than or equal to operator
*
* @param other the date to compare
*/
bool operator<=(const KLocalizedDate &other) const;
/**
* QDate less than or equal to operator
*
* @param other the date to compare
*/
bool operator<=(const QDate &other) const;
/**
* KLocalizedDate greater than operator
*
* @param other the date to compare
*/
bool operator>(const KLocalizedDate &other) const;
/**
* QDate greater than operator
*
* @param other the date to compare
*/
bool operator>(const QDate &other) const;
/**
* KLocalizedDate greater than or equal to operator
*
* @param other the date to compare
*/
bool operator>=(const KLocalizedDate &other) const;
/**
* QDate greater than or equal to operator
*
* @param other the date to compare
*/
bool operator>=(const QDate &other) const;
private:
friend QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date);
friend QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date);
friend QDebug KDECORE_EXPORT operator<<(QDebug, const KLocalizedDate &);
QSharedDataPointer<KLocalizedDatePrivate> d;
};
Q_DECLARE_METATYPE(KLocalizedDate)
/**
* Data stream output operator
*
* @param out the datastream to write to
* @param date the date to write to the stream
*/
QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date);
/**
* Data stream input operator
*
* @param in the datastream to read from
* @param date the date to read from the stream
*/
QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date);
/**
* Debug stream output operator
*
* @param debug the debug datastream to write to
* @param date the date to write to the stream
*/
QDebug KDECORE_EXPORT operator<<(QDebug debug, const KLocalizedDate &date);
#endif // KLOCALIZEDDATE_H
|