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 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078
|
/////////////////////////////////////////////////////////////////////////////
// Name: datetime.h
// Purpose: interface of wxDateTime
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
@class wxDateTime
wxDateTime class represents an absolute moment in time.
The type @c wxDateTime_t is typedefed as <tt>unsigned short</tt> and is
used to contain the number of years, hours, minutes, seconds and
milliseconds.
Global constant ::wxDefaultDateTime and synonym for it ::wxInvalidDateTime are
defined. This constant will be different from any valid wxDateTime object.
@section datetime_static Static Functions
All static functions either set or return the static variables of
wxDateSpan (the country), return the current moment, year, month or number
of days in it, or do some general calendar-related actions.
Please note that although several function accept an extra Calendar
parameter, it is currently ignored as only the Gregorian calendar is
supported. Future versions will support other calendars.
@section datetime_formatting Date Formatting and Parsing
The date formatting and parsing functions convert wxDateTime objects to and
from text. The conversions to text are mostly trivial: you can either do it
using the default date and time representations for the current locale
(FormatDate() and FormatTime()), using the international standard
representation defined by ISO 8601 (FormatISODate(), FormatISOTime() and
FormatISOCombined()) or by specifying any format at all and using Format()
directly.
The conversions from text are more interesting, as there are much more
possibilities to care about. The simplest cases can be taken care of with
ParseFormat() which can parse any date in the given (rigid) format.
ParseRfc822Date() is another function for parsing dates in predefined
format -- the one of RFC 822 which (still...) defines the format of email
messages on the Internet. This format cannot be described with
@c strptime(3)-like format strings used by Format(), hence the need for a
separate function.
But the most interesting functions are ParseTime(), ParseDate() and
ParseDateTime(). They try to parse the date and time (or only one of them)
in 'free' format, i.e. allow them to be specified in any of possible ways.
These functions will usually be used to parse the (interactive) user input
which is not bound to be in any predefined format. As an example,
ParseDate() can parse the strings such as "tomorrow", "March first" and
even "next Sunday".
Finally notice that each of the parsing functions is available in several
overloads: if the input string is a narrow (@c char *) string, then a
narrow pointer is returned. If the input string is a wide string, a wide
char pointer is returned. Finally, if the input parameter is a wxString, a
narrow char pointer is also returned for backwards compatibility but there
is also an additional argument of wxString::const_iterator type in which,
if it is not @NULL, an iterator pointing to the end of the scanned string
part is returned.
@library{wxbase}
@category{data}
@stdobjects
- ::wxDefaultDateTime
@see @ref overview_datetime, wxTimeSpan, wxDateSpan, wxCalendarCtrl
*/
class wxDateTime
{
public:
/**
A small unsigned integer type for storing things like minutes,
seconds &c. It should be at least short (i.e. not char) to contain
the number of milliseconds - it may also be 'int' because there is
no size penalty associated with it in our code, we don't store any
data in this format.
*/
typedef unsigned short wxDateTime_t;
/**
Time zone symbolic names.
*/
enum TZ
{
/// the time in the current time zone
Local,
//@{
/// zones from GMT (= Greenwich Mean Time): they're guaranteed to be
/// consequent numbers, so writing something like `GMT0 + offset' is
/// safe if abs(offset) <= 12
// underscore stands for minus
GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
GMT0,
GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13,
// Note that GMT12 and GMT_12 are not the same: there is a difference
// of exactly one day between them
//@}
// some symbolic names for TZ
// Europe
WET = GMT0, //!< Western Europe Time
WEST = GMT1, //!< Western Europe Summer Time
CET = GMT1, //!< Central Europe Time
CEST = GMT2, //!< Central Europe Summer Time
EET = GMT2, //!< Eastern Europe Time
EEST = GMT3, //!< Eastern Europe Summer Time
MSK = GMT3, //!< Moscow Time
MSD = GMT4, //!< Moscow Summer Time
// US and Canada
AST = GMT_4, //!< Atlantic Standard Time
ADT = GMT_3, //!< Atlantic Daylight Time
EST = GMT_5, //!< Eastern Standard Time
EDT = GMT_4, //!< Eastern Daylight Saving Time
CST = GMT_6, //!< Central Standard Time
CDT = GMT_5, //!< Central Daylight Saving Time
MST = GMT_7, //!< Mountain Standard Time
MDT = GMT_6, //!< Mountain Daylight Saving Time
PST = GMT_8, //!< Pacific Standard Time
PDT = GMT_7, //!< Pacific Daylight Saving Time
HST = GMT_10, //!< Hawaiian Standard Time
AKST = GMT_9, //!< Alaska Standard Time
AKDT = GMT_8, //!< Alaska Daylight Saving Time
// Australia
A_WST = GMT8, //!< Western Standard Time
A_CST = GMT13 + 1, //!< Central Standard Time (+9.5)
A_EST = GMT10, //!< Eastern Standard Time
A_ESST = GMT11, //!< Eastern Summer Time
// New Zealand
NZST = GMT12, //!< Standard Time
NZDT = GMT13, //!< Daylight Saving Time
/// Universal Coordinated Time = the new and politically correct name
/// for GMT.
UTC = GMT0
};
/**
Several functions accept an extra parameter specifying the calendar to use
(although most of them only support now the Gregorian calendar). This
parameters is one of the following values.
*/
enum Calendar
{
Gregorian, ///< calendar currently in use in Western countries
Julian ///< calendar in use since -45 until the 1582 (or later)
};
/**
Date calculations often depend on the country and wxDateTime allows to set
the country whose conventions should be used using SetCountry(). It takes
one of the following values as parameter.
*/
enum Country
{
Country_Unknown, ///< no special information for this country
Country_Default, ///< set the default country with SetCountry() method
///< or use the default country with any other
Country_WesternEurope_Start,
Country_EEC = Country_WesternEurope_Start,
France,
Germany,
UK,
Country_WesternEurope_End = UK,
Russia,
USA
};
/// symbolic names for the months
enum Month
{
Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec,
/// Invalid month value.
Inv_Month
};
/// symbolic names for the weekdays
enum WeekDay
{
Sun, Mon, Tue, Wed, Thu, Fri, Sat,
/// Invalid week day value.
Inv_WeekDay
};
/// invalid value for the year
enum Year
{
Inv_Year = SHRT_MIN // should hold in wxDateTime_t
};
/**
Flags to be used with GetMonthName() and GetWeekDayName() functions.
*/
enum NameFlags
{
Name_Full = 0x01, ///< return full name
Name_Abbr = 0x02 ///< return abbreviated name
};
/**
Different parts of the world use different conventions for the week start.
In some countries, the week starts on Sunday, while in others -- on Monday.
The ISO standard doesn't address this issue, so we support both conventions
in the functions whose result depends on it (GetWeekOfYear() and
GetWeekOfMonth()).
The desired behaviour may be specified by giving one of the following
constants as argument to these functions.
*/
enum WeekFlags
{
Default_First, ///< Sunday_First for US, Monday_First for the rest
Monday_First, ///< week starts with a Monday
Sunday_First ///< week starts with a Sunday
};
/**
Class representing a time zone.
The representation is simply the offset, in seconds, from UTC.
*/
class WXDLLIMPEXP_BASE TimeZone
{
public:
/// Constructor for a named time zone.
TimeZone(TZ tz);
/// Constructor for the given offset in seconds.
TimeZone(long offset = 0);
/// Create a time zone with the given offset in seconds.
static TimeZone Make(long offset);
/// Return the offset of this time zone from UTC, in seconds.
long GetOffset() const;
};
/**
Contains broken down date-time representation.
This struct is analogous to standard C <code>struct tm</code> and uses
the same, not always immediately obvious, conventions for its members:
notably its mon and mday fields count from 0 while yday counts from 1.
*/
struct Tm
{
wxDateTime_t msec, ///< Number of milliseconds.
sec, ///< Seconds in 0..59 (60 with leap seconds) range.
min, ///< Minutes in 0..59 range.
hour, ///< Hours since midnight in 0..23 range.
mday, ///< Day of the month in 1..31 range.
yday; ///< Day of the year in 0..365 range.
Month mon; ///< Month, as an enumerated constant.
int year; ///< Year.
/**
Check if the given date/time is valid (in Gregorian calendar).
Return @false if the components don't correspond to a correct date.
*/
bool IsValid() const;
/**
Return the week day corresponding to this date.
Unlike the other fields, the week day is not always available and
so must be accessed using this method as it is computed on demand
when it is called.
*/
WeekDay GetWeekDay();
};
/**
@name Constructors, Assignment Operators and Setters
Constructors and various Set() methods are collected here. If you
construct a date object from separate values for day, month and year,
you should use IsValid() method to check that the values were correct
as constructors cannot return an error code.
*/
//@{
/**
Default constructor. Use one of the Set() functions to initialize the
object later.
*/
wxDateTime();
/**
Copy constructor.
*/
wxDateTime(const wxDateTime& date);
/**
Same as Set().
*/
wxDateTime(time_t timet);
/**
Same as Set().
*/
wxDateTime(const struct tm& tm);
/**
Same as Set().
*/
wxDateTime(double jdn);
/**
Same as Set().
*/
wxDateTime(wxDateTime_t hour, wxDateTime_t minute = 0,
wxDateTime_t second = 0, wxDateTime_t millisec = 0);
/**
Same as Set().
*/
wxDateTime(wxDateTime_t day, Month month,
int year = Inv_Year, wxDateTime_t hour = 0,
wxDateTime_t minute = 0, wxDateTime_t second = 0,
wxDateTime_t millisec = 0);
/**
Same as SetFromMSWSysTime.
@param st
Input, Windows SYSTEMTIME reference
@since 2.9.0
@remarks MSW only
@onlyfor{wxmsw}
*/
wxDateTime(const struct _SYSTEMTIME& st);
/**
Reset time to midnight (00:00:00) without changing the date.
*/
wxDateTime& ResetTime();
/**
Constructs the object from @a timet value holding the number of seconds
since Jan 1, 1970 UTC.
If @a timet is invalid, i.e. @code (time_t)-1 @endcode, wxDateTime
becomes invalid too, i.e. its IsValid() will return @false.
*/
wxDateTime& Set(time_t timet);
/**
Sets the date and time from the broken down representation in the
standard @a tm structure.
*/
wxDateTime& Set(const struct tm& tm);
/**
Sets the date and time from the broken down representation in the
@a wxDateTime::Tm structure.
*/
wxDateTime& Set(const Tm& tm);
/**
Sets the date from the so-called Julian Day Number.
By definition, the Julian Day Number, usually abbreviated as JDN, of a
particular instant is the fractional number of days since 12 hours
Universal Coordinated Time (Greenwich mean noon) on January 1 of the
year -4712 in the Julian proleptic calendar.
*/
wxDateTime& Set(double jdn);
/**
Sets the date to be equal to Today() and the time from supplied
parameters.
See the full Set() overload for the remarks about DST.
*/
wxDateTime& Set(wxDateTime_t hour, wxDateTime_t minute = 0,
wxDateTime_t second = 0, wxDateTime_t millisec = 0);
/**
Sets the date and time from the parameters.
If the function parameters are invalid, e.g. @a month is February and
@a day is 30, the object is left in an invalid state, i.e. IsValid()
method will return @false.
If the specified time moment is invalid due to DST, i.e. it falls into
the "missing" hour on the date on which the DST starts, a valid
wxDateTime object is still constructed but its hour component is moved
forward to ensure that it corresponds to a valid moment in the local
time zone. For example, in the CET time zone the DST started on
2013-03-31T02:00:00 in 2013 and so setting the object to 2:30 at this
date actually sets the hour to 3, and not 2.
*/
wxDateTime& Set(wxDateTime_t day, Month month,
int year = Inv_Year, wxDateTime_t hour = 0,
wxDateTime_t minute = 0, wxDateTime_t second = 0,
wxDateTime_t millisec = 0);
/**
Sets the day without changing other date components.
*/
wxDateTime& SetDay(unsigned short day);
/**
Sets the date from the date and time in DOS format.
*/
wxDateTime& SetFromDOS(unsigned long ddt);
/**
Sets the hour without changing other date components.
*/
wxDateTime& SetHour(unsigned short hour);
/**
Sets the millisecond without changing other date components.
*/
wxDateTime& SetMillisecond(unsigned short millisecond);
/**
Sets the minute without changing other date components.
*/
wxDateTime& SetMinute(unsigned short minute);
/**
Sets the month without changing other date components.
*/
wxDateTime& SetMonth(Month month);
/**
Sets the second without changing other date components.
*/
wxDateTime& SetSecond(unsigned short second);
/**
Sets the date and time of to the current values. Same as assigning the
result of Now() to this object.
*/
wxDateTime& SetToCurrent();
/**
Sets the year without changing other date components.
*/
wxDateTime& SetYear(int year);
/**
Same as Set().
*/
wxDateTime& operator=(time_t timet);
/**
Same as Set().
*/
wxDateTime& operator=(const struct tm& tm);
//@}
/**
@name Accessors
Here are the trivial accessors. Other functions, which might have to
perform some more complicated calculations to find the answer are under
the "Date Arithmetics" section.
*/
//@{
/**
Returns the date and time in DOS format.
*/
unsigned long GetAsDOS() const;
/**
Initialize using the Windows SYSTEMTIME structure.
@param st
Input, Windows SYSTEMTIME reference
@since 2.9.0
@remarks MSW only
@onlyfor{wxmsw}
*/
wxDateTime& SetFromMSWSysTime(const struct _SYSTEMTIME& st);
/**
Returns the date and time in the Windows SYSTEMTIME format.
@param st
Output, pointer to Windows SYSTEMTIME
@since 2.9.0
@remarks MSW only
@onlyfor{wxmsw}
*/
void GetAsMSWSysTime(struct _SYSTEMTIME* st) const;
/**
Returns the century of this date.
*/
int GetCentury(const TimeZone& tz = Local) const;
/**
Returns the object having the same date component as this one but time
of 00:00:00.
@since 2.8.2
@see ResetTime()
*/
wxDateTime GetDateOnly() const;
/**
Returns the day in the given timezone (local one by default).
*/
unsigned short GetDay(const TimeZone& tz = Local) const;
/**
Returns the day of the year (in 1-366 range) in the given timezone
(local one by default).
*/
unsigned short GetDayOfYear(const TimeZone& tz = Local) const;
/**
Returns the hour in the given timezone (local one by default).
*/
unsigned short GetHour(const TimeZone& tz = Local) const;
/**
Returns the milliseconds in the given timezone (local one by default).
*/
unsigned short GetMillisecond(const TimeZone& tz = Local) const;
/**
Returns the minute in the given timezone (local one by default).
*/
unsigned short GetMinute(const TimeZone& tz = Local) const;
/**
Returns the month in the given timezone (local one by default).
*/
Month GetMonth(const TimeZone& tz = Local) const;
/**
Returns the seconds in the given timezone (local one by default).
*/
unsigned short GetSecond(const TimeZone& tz = Local) const;
/**
Returns the number of seconds since Jan 1, 1970 UTC.
An assert failure will occur if the date is not in the range covered by
@c time_t type, use GetValue() if you work with dates outside of it.
*/
time_t GetTicks() const;
/**
Returns broken down representation of the date and time.
*/
Tm GetTm(const TimeZone& tz = Local) const;
/**
Returns the week day in the given timezone (local one by default).
*/
WeekDay GetWeekDay(const TimeZone& tz = Local) const;
/**
Returns the ordinal number of the week in the month (in 1-5 range).
As GetWeekOfYear(), this function supports both conventions for the
week start.
*/
wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
const TimeZone& tz = Local) const;
/**
Returns the number of the week of the year this date is in. The first
week of the year is, according to international standards, the one
containing Jan 4 or, equivalently, the first week which has Thursday in
this year. Both of these definitions are the same as saying that the
first week of the year must contain more than half of its days in this
year. Accordingly, the week number will always be in 1-53 range (52 for
non-leap years).
The function depends on the week start convention specified by the @a flags
argument but its results for @c Sunday_First are not well-defined as the
ISO definition quoted above applies to the weeks starting on Monday only.
*/
wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
const TimeZone& tz = Local) const;
/**
Returns the year in the given timezone (local one by default).
*/
int GetYear(const TimeZone& tz = Local) const;
/**
Returns @true if the object represents a valid time moment.
*/
bool IsValid() const;
/**
Returns @true is this day is not a holiday in the given country.
*/
bool IsWorkDay(Country country = Country_Default) const;
//@}
/**
@name Date Comparison
There are several functions to allow date comparison. To supplement
them, a few global operators, etc taking wxDateTime are defined.
*/
//@{
/**
Returns @true if this date precedes the given one.
*/
bool IsEarlierThan(const wxDateTime& datetime) const;
/**
Returns @true if the two dates are strictly identical.
*/
bool IsEqualTo(const wxDateTime& datetime) const;
/**
Returns @true if the date is equal to another one up to the given time
interval, i.e.\ if the absolute difference between the two dates is less
than this interval.
*/
bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
/**
Returns @true if this date is later than the given one.
*/
bool IsLaterThan(const wxDateTime& datetime) const;
/**
Returns @true if the date is the same without comparing the time parts.
*/
bool IsSameDate(const wxDateTime& dt) const;
/**
Returns @true if the time is the same (although dates may differ).
*/
bool IsSameTime(const wxDateTime& dt) const;
/**
Returns @true if this date lies strictly between the two given dates.
@see IsBetween()
*/
bool IsStrictlyBetween(const wxDateTime& t1,
const wxDateTime& t2) const;
/**
Returns @true if IsStrictlyBetween() is @true or if the date is equal
to one of the limit values.
@see IsStrictlyBetween()
*/
bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
//@}
/**
@name Date Arithmetics
These functions carry out
@ref overview_datetime_arithmetics "arithmetics" on the wxDateTime
objects. As explained in the overview, either wxTimeSpan or wxDateSpan
may be added to wxDateTime, hence all functions are overloaded to
accept both arguments.
Also, both Add() and Subtract() have both const and non-const version.
The first one returns a new object which represents the sum/difference
of the original one with the argument while the second form modifies
the object to which it is applied. The operators "-=" and "+=" are
defined to be equivalent to the second forms of these functions.
*/
//@{
/**
Adds the given date span to this object.
*/
wxDateTime Add(const wxDateSpan& diff) const;
/**
Adds the given date span to this object.
*/
wxDateTime& Add(const wxDateSpan& diff);
/**
Adds the given time span to this object.
*/
wxDateTime Add(const wxTimeSpan& diff) const;
/**
Adds the given time span to this object.
*/
wxDateTime& Add(const wxTimeSpan& diff);
/**
Subtracts the given time span from this object.
*/
wxDateTime Subtract(const wxTimeSpan& diff) const;
/**
Subtracts the given time span from this object.
*/
wxDateTime& Subtract(const wxTimeSpan& diff);
/**
Subtracts the given date span from this object.
*/
wxDateTime Subtract(const wxDateSpan& diff) const;
/**
Subtracts the given date span from this object.
*/
wxDateTime& Subtract(const wxDateSpan& diff);
/**
Subtracts another date from this one and returns the difference between
them as a wxTimeSpan.
*/
wxTimeSpan Subtract(const wxDateTime& dt) const;
/**
Returns the difference between this object and @a dt as a wxDateSpan.
This method allows to find the number of entire years, months, weeks and
days between @a dt and this date.
@since 2.9.5
*/
wxDateSpan DiffAsDateSpan(const wxDateTime& dt) const;
/**
Adds the given date span to this object.
*/
wxDateTime& operator+=(const wxDateSpan& diff);
/**
Adds the given date span to this object.
*/
wxDateTime operator+(const wxDateSpan& ds) const;
/**
Subtracts the given date span from this object.
*/
wxDateTime& operator-=(const wxDateSpan& diff);
/**
Subtracts the given date span from this object.
*/
wxDateTime operator-(const wxDateSpan& ds) const;
/**
Adds the given time span to this object.
*/
wxDateTime& operator+=(const wxTimeSpan& diff);
/**
Adds the given time span to this object.
*/
wxDateTime operator+(const wxTimeSpan& ts) const;
/**
Subtracts the given time span from this object.
*/
wxDateTime& operator-=(const wxTimeSpan& diff);
/**
Subtracts the given time span from this object.
*/
wxDateTime operator-(const wxTimeSpan& ts) const;
/**
Subtracts another date from this one and returns the difference between
them as a wxTimeSpan.
*/
wxTimeSpan operator-(const wxDateTime& dt2) const;
//@}
/**
@name Date Formatting and Parsing
See @ref datetime_formatting
*/
//@{
/**
This function does the same as the standard ANSI C @c strftime(3)
function (http://www.cplusplus.com/reference/clibrary/ctime/strftime.html).
Please see its description for the meaning of @a format parameter.
Notice that POSIX @c "%g", @c "%G", @c "%V" and @c "%z" format
specifiers are supported even if the standard library doesn't support
them (e.g. MSVC).
It also accepts a few wxWidgets-specific extensions: you can optionally
specify the width of the field to follow using @c printf(3)-like syntax
and the format specification @c "%l" can be used to get the number of
milliseconds.
@see ParseFormat()
*/
wxString Format(const wxString& format = wxDefaultDateTimeFormat,
const TimeZone& tz = Local) const;
/**
Identical to calling Format() with @c "%x" argument (which means
"preferred date representation for the current locale").
*/
wxString FormatDate() const;
/**
Returns the combined date-time representation in the ISO 8601 format
@c "YYYY-MM-DDTHH:MM:SS". The @a sep parameter default value produces
the result exactly corresponding to the ISO standard, but it can also
be useful to use a space as separator if a more human-readable combined
date-time representation is needed.
@see FormatISODate(), FormatISOTime(), ParseISOCombined()
*/
wxString FormatISOCombined(char sep = 'T') const;
/**
This function returns the date representation in the ISO 8601 format
@c "YYYY-MM-DD".
*/
wxString FormatISODate() const;
/**
This function returns the time representation in the ISO 8601 format
@c "HH:MM:SS".
*/
wxString FormatISOTime() const;
/**
Identical to calling Format() with @c "%X" argument (which means
"preferred time representation for the current locale").
*/
wxString FormatTime() const;
/**
This function is like ParseDateTime(), but it only allows the date to
be specified.
It is thus less flexible then ParseDateTime(), but also has less
chances to misinterpret the user input.
See ParseFormat() for the description of function parameters and return
value.
@see Format()
*/
bool ParseDate(const wxString& date, wxString::const_iterator *end);
/**
Parses the string @a datetime containing the date and time in free
format.
This function tries as hard as it can to interpret the given string as
date and time. Unlike ParseRfc822Date(), it will accept anything that
may be accepted and will only reject strings which cannot be parsed in
any way at all. Notice that the function will fail if either date or
time part is present but not both, use ParseDate() or ParseTime() to
parse strings containing just the date or time component.
See ParseFormat() for the description of function parameters and return
value.
*/
bool ParseDateTime(const wxString& datetime, wxString::const_iterator *end);
/**
This function parses the string @a date according to the given
@e format. The system @c strptime(3) function is used whenever
available, but even if it is not, this function is still implemented,
although support for locale-dependent format specifiers such as
@c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
as @c "%z" and @c "%Z" are not implemented. This function does handle
the month and weekday names in the current locale on all platforms,
however.
Please see the description of the ANSI C function @c strftime(3) for
the syntax of the format string.
The @a dateDef parameter is used to fill in the fields which could not
be determined from the format string. For example, if the format is
@c "%d" (the day of the month), the month and the year are taken from
@a dateDef. If it is not specified, Today() is used as the default
date.
Example of using this function:
@code
wxDateTime dt;
wxString str = "...";
wxString::const_iterator end;
if ( !dt.ParseFormat(str, "%Y-%m-%d", &end) )
... parsing failed ...
else if ( end == str.end() )
... entire string parsed ...
else
... wxString(end, str.end()) left over ...
@endcode
@param date
The string to be parsed.
@param format
strptime()-like format string.
@param dateDef
Used to fill in the date components not specified in the @a date
string.
@param end
Will be filled with the iterator pointing to the location where the
parsing stopped if the function returns @true. If the entire string
was consumed, it is set to @c date.end(). Notice that this argument
must be non-@NULL.
@return
@true if at least part of the string was parsed successfully,
@false otherwise.
@see Format()
*/
bool ParseFormat(const wxString& date,
const wxString& format,
const wxDateTime& dateDef,
wxString::const_iterator *end);
/**
@overload
*/
bool ParseFormat(const wxString& date,
const wxString& format,
wxString::const_iterator *end);
/**
@overload
*/
bool ParseFormat(const wxString& date, wxString::const_iterator *end);
/**
This function parses the string containing the date and time in ISO
8601 combined format @c "YYYY-MM-DDTHH:MM:SS". The separator between
the date and time parts must be equal to @a sep for the function to
succeed.
@return @true if the entire string was parsed successfully, @false
otherwise.
*/
bool ParseISOCombined(const wxString& date, char sep = 'T');
/**
This function parses the date in ISO 8601 format @c "YYYY-MM-DD".
@return @true if the entire string was parsed successfully, @false
otherwise.
*/
bool ParseISODate(const wxString& date);
/**
This function parses the time in ISO 8601 format @c "HH:MM:SS".
@return @true if the entire string was parsed successfully, @false
otherwise.
*/
bool ParseISOTime(const wxString& date);
/**
Parses the string @a date looking for a date formatted according to the
RFC 822 in it. The exact description of this format may, of course, be
found in the RFC (section 5), but, briefly, this is the format used in
the headers of Internet email messages and one of the most common
strings expressing date in this format may be something like
@c "Sat, 18 Dec 1999 00:48:30 +0100".
Returns @NULL if the conversion failed, otherwise return the pointer to
the character immediately following the part of the string which could
be parsed. If the entire string contains only the date in RFC 822
format, the returned pointer will be pointing to a @c NUL character.
This function is intentionally strict, it will return an error for any
string which is not RFC 822 compliant. If you need to parse date
formatted in more free ways, you should use ParseDateTime() or
ParseDate() instead.
See ParseFormat() for the description of function parameters and return
value.
*/
bool ParseRfc822Date(const wxString& date, wxString::const_iterator *end);
/**
This functions is like ParseDateTime(), but only allows the time to be
specified in the input string.
See ParseFormat() for the description of function parameters and return
value.
*/
bool ParseTime(const wxString& time, wxString::const_iterator *end);
//@}
/**
@name Calendar Calculations
The functions in this section perform the basic calendar calculations,
mostly related to the week days. They allow to find the given week day
in the week with given number (either in the month or in the year) and
so on.
None of the functions in this section modify the time part of the
wxDateTime, they only work with the date part of it.
*/
//@{
/**
Returns the copy of this object to which SetToLastMonthDay() was
applied.
*/
wxDateTime GetLastMonthDay(Month month = Inv_Month,
int year = Inv_Year) const;
/**
Returns the copy of this object to which SetToLastWeekDay() was
applied.
*/
wxDateTime GetLastWeekDay(WeekDay weekday, Month month = Inv_Month,
int year = Inv_Year);
/**
Returns the copy of this object to which SetToNextWeekDay() was
applied.
*/
wxDateTime GetNextWeekDay(WeekDay weekday) const;
/**
Returns the copy of this object to which SetToPrevWeekDay() was
applied.
*/
wxDateTime GetPrevWeekDay(WeekDay weekday) const;
/**
Returns the copy of this object to which SetToWeekDay() was applied.
*/
wxDateTime GetWeekDay(WeekDay weekday, int n = 1, Month month = Inv_Month,
int year = Inv_Year) const;
/**
Returns the copy of this object to which SetToWeekDayInSameWeek() was
applied.
*/
wxDateTime GetWeekDayInSameWeek(WeekDay weekday,
WeekFlags flags = Monday_First) const;
/**
Returns the copy of this object to which SetToYearDay() was applied.
*/
wxDateTime GetYearDay(wxDateTime_t yday) const;
/**
Sets the date to the last day in the specified month (the current one
by default).
@return The reference to the modified object itself.
*/
wxDateTime& SetToLastMonthDay(Month month = Inv_Month, int year = Inv_Year);
/**
The effect of calling this function is the same as of calling
@c SetToWeekDay(-1, weekday, month, year). The date will be set to the
last @a weekday in the given month and year (the current ones by
default). Always returns @true.
*/
bool SetToLastWeekDay(WeekDay weekday, Month month = Inv_Month,
int year = Inv_Year);
/**
Sets the date so that it will be the first @a weekday following the
current date.
@return The reference to the modified object itself.
*/
wxDateTime& SetToNextWeekDay(WeekDay weekday);
/**
Sets the date so that it will be the last @a weekday before the current
date.
@return The reference to the modified object itself.
*/
wxDateTime& SetToPrevWeekDay(WeekDay weekday);
/**
Sets the date to the @e n-th @a weekday in the given month of the given
year (the current month and year are used by default). The parameter
@a n may be either positive (counting from the beginning of the month)
or negative (counting from the end of it).
For example, SetToWeekDay(2, wxDateTime::Wed) will set the date to the
second Wednesday in the current month and
SetToWeekDay(-1, wxDateTime::Sun) will set the date to the last Sunday
in the current month.
@return @true if the date was modified successfully, @false otherwise
meaning that the specified date doesn't exist.
*/
bool SetToWeekDay(WeekDay weekday, int n = 1,
Month month = Inv_Month, int year = Inv_Year);
/**
Adjusts the date so that it will still lie in the same week as before,
but its week day will be the given one.
@return The reference to the modified object itself.
*/
wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday,
WeekFlags flags = Monday_First);
/**
Sets the date to the day number @a yday in the same year (i.e.\ unlike
the other functions, this one does not use the current year). The day
number should be in the range 1-366 for the leap years and 1-365 for
the other ones.
@return The reference to the modified object itself.
*/
wxDateTime& SetToYearDay(wxDateTime_t yday);
//@}
/**
@name Astronomical/Historical Functions
Some degree of support for the date units used in astronomy and/or
history is provided. You can construct a wxDateTime object from a
JDN and you may also get its JDN, MJD or Rata Die number from it.
Related functions in other groups: wxDateTime(double), Set(double)
*/
//@{
/**
Synonym for GetJulianDayNumber().
*/
double GetJDN() const;
/**
Returns the JDN corresponding to this date. Beware of rounding errors!
@see GetModifiedJulianDayNumber()
*/
double GetJulianDayNumber() const;
/**
Synonym for GetModifiedJulianDayNumber().
*/
double GetMJD() const;
/**
Returns the @e "Modified Julian Day Number" (MJD) which is, by
definition, is equal to JDN - 2400000.5.
The MJDs are simpler to work with as the integral MJDs correspond to
midnights of the dates in the Gregorian calendar and not the noons like
JDN. The MJD 0 represents Nov 17, 1858.
*/
double GetModifiedJulianDayNumber() const;
/**
Return the @e Rata Die number of this date.
By definition, the Rata Die number is a date specified as the number of
days relative to a base date of December 31 of the year 0. Thus January
1 of the year 1 is Rata Die day 1.
*/
double GetRataDie() const;
//@}
/**
@name Time Zone and DST Support
Please see the @ref overview_datetime_timezones "time zone overview"
for more information about time zones. Normally, these functions should
be rarely used.
Related functions in other groups: GetBeginDST(), GetEndDST()
*/
//@{
/**
Transform the date from the given time zone to the local one. If
@a noDST is @true, no DST adjustments will be made.
@return The date in the local time zone.
*/
wxDateTime FromTimezone(const TimeZone& tz, bool noDST = false) const;
/**
Returns @true if the DST is applied for this date in the given country.
@see GetBeginDST(), GetEndDST()
*/
int IsDST(Country country = Country_Default) const;
/**
Same as FromTimezone() but modifies the object in place.
*/
wxDateTime& MakeFromTimezone(const TimeZone& tz, bool noDST = false);
/**
Modifies the object in place to represent the date in another time
zone. If @a noDST is @true, no DST adjustments will be made.
*/
wxDateTime& MakeTimezone(const TimeZone& tz, bool noDST = false);
/**
This is the same as calling MakeTimezone() with the argument @c GMT0.
*/
wxDateTime& MakeUTC(bool noDST = false);
/**
Transform the date to the given time zone. If @a noDST is @true, no DST
adjustments will be made.
@return The date in the new time zone.
*/
wxDateTime ToTimezone(const TimeZone& tz, bool noDST = false) const;
/**
This is the same as calling ToTimezone() with the argument @c GMT0.
*/
wxDateTime ToUTC(bool noDST = false) const;
//@}
/**
Converts the year in absolute notation (i.e.\ a number which can be
negative, positive or zero) to the year in BC/AD notation. For the
positive years, nothing is done, but the year 0 is year 1 BC and so for
other years there is a difference of 1.
This function should be used like this:
@code
wxDateTime dt(...);
int y = dt.GetYear();
printf("The year is %d%s", wxDateTime::ConvertYearToBC(y), y > 0 ? "AD" : "BC");
@endcode
*/
static int ConvertYearToBC(int year);
/**
Returns the translations of the strings @c AM and @c PM used for time
formatting for the current locale. Either of the pointers may be @NULL
if the corresponding value is not needed.
*/
static void GetAmPmStrings(wxString* am, wxString* pm);
/**
Get the beginning of DST for the given country in the given year
(current one by default). This function suffers from limitations
described in the @ref overview_datetime_dst "DST overview".
@see GetEndDST()
*/
static wxDateTime GetBeginDST(int year = Inv_Year,
Country country = Country_Default);
/**
Returns the end of DST for the given country in the given year (current
one by default).
@see GetBeginDST()
*/
static wxDateTime GetEndDST(int year = Inv_Year,
Country country = Country_Default);
/**
Get the current century, i.e.\ first two digits of the year, in given
calendar (only Gregorian is currently supported).
*/
static int GetCentury(int year);
/**
Returns the current default country. The default country is used for
DST calculations, for example.
@see SetCountry()
*/
static Country GetCountry();
/**
Get the current month in given calendar (only Gregorian is currently
supported).
*/
static Month GetCurrentMonth(Calendar cal = Gregorian);
/**
Get the current year in given calendar (only Gregorian is currently
supported).
*/
static int GetCurrentYear(Calendar cal = Gregorian);
/**
Return the standard English name of the given month.
This function always returns "January" or "Jan" for January, use
GetMonthName() to retrieve the name of the month in the users current
locale.
@param month
One of wxDateTime::Jan, ..., wxDateTime::Dec values.
@param flags
Either Name_Full (default) or Name_Abbr.
@see GetEnglishWeekDayName()
@since 2.9.0
*/
static wxString GetEnglishMonthName(Month month,
NameFlags flags = Name_Full);
/**
Return the standard English name of the given week day.
This function always returns "Monday" or "Mon" for Monday, use
GetWeekDayName() to retrieve the name of the month in the users current
locale.
@param weekday
One of wxDateTime::Sun, ..., wxDateTime::Sat values.
@param flags
Either Name_Full (default) or Name_Abbr.
@see GetEnglishMonthName()
@since 2.9.0
*/
static wxString GetEnglishWeekDayName(WeekDay weekday,
NameFlags flags = Name_Full);
/**
Gets the full (default) or abbreviated name of the given month.
This function returns the name in the current locale, use
GetEnglishMonthName() to get the untranslated name if necessary.
@param month
One of wxDateTime::Jan, ..., wxDateTime::Dec values.
@param flags
Either Name_Full (default) or Name_Abbr.
@see GetWeekDayName()
*/
static wxString GetMonthName(Month month, NameFlags flags = Name_Full);
/**
Returns the number of days in the given year. The only supported value
for @a cal currently is @c Gregorian.
*/
static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
/**
Returns the number of days in the given month of the given year. The
only supported value for @a cal currently is @c Gregorian.
*/
static wxDateTime_t GetNumberOfDays(Month month, int year = Inv_Year,
Calendar cal = Gregorian);
/**
Returns the current time.
*/
static time_t GetTimeNow();
/**
Returns the current time broken down using the buffer whose address is
passed to the function with @a tm to store the result.
*/
static tm* GetTmNow(struct tm *tm);
/**
Returns the current time broken down. Note that this function returns a
pointer to a static buffer that's reused by calls to this function and
certain C library functions (e.g. localtime). If there is any chance
your code might be used in a multi-threaded application, you really
should use GetTmNow(struct tm *) instead.
*/
static tm* GetTmNow();
/**
Gets the full (default) or abbreviated name of the given week day.
This function returns the name in the current locale, use
GetEnglishWeekDayName() to get the untranslated name if necessary.
@param weekday
One of wxDateTime::Sun, ..., wxDateTime::Sat values.
@param flags
Either Name_Full (default) or Name_Abbr.
@see GetMonthName()
*/
static wxString GetWeekDayName(WeekDay weekday,
NameFlags flags = Name_Full);
/**
Returns @true if DST was used in the given year (the current one by
default) in the given country.
*/
static bool IsDSTApplicable(int year = Inv_Year,
Country country = Country_Default);
/**
Returns @true if the @a year is a leap one in the specified calendar.
This functions supports Gregorian and Julian calendars.
*/
static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
/**
This function returns @true if the specified (or default) country is
one of Western European ones. It is used internally by wxDateTime to
determine the DST convention and date and time formatting rules.
*/
static bool IsWestEuropeanCountry(Country country = Country_Default);
/**
Returns the object corresponding to the current time.
Example:
@code
wxDateTime now = wxDateTime::Now();
printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
@endcode
@note This function is accurate up to seconds. UNow() can be used if
better precision is required.
@see Today()
*/
static wxDateTime Now();
/**
Sets the country to use by default. This setting influences the DST
calculations, date formatting and other things.
@see GetCountry()
*/
static void SetCountry(Country country);
/**
Set the date to the given @a weekday in the week number @a numWeek of
the given @a year . The number should be in range 1-53.
Note that the returned date may be in a different year than the one
passed to this function because both the week 1 and week 52 or 53 (for
leap years) contain days from different years. See GetWeekOfYear() for
the explanation of how the year weeks are counted.
*/
static wxDateTime SetToWeekOfYear(int year, wxDateTime_t numWeek,
WeekDay weekday = Mon);
/**
Returns the object corresponding to the midnight of the current day
(i.e.\ the same as Now(), but the time part is set to 0).
@see Now()
*/
static wxDateTime Today();
/**
Returns the object corresponding to the current UTC time including the
milliseconds.
Notice that unlike Now(), this method creates a wxDateTime object
corresponding to UTC, not local, time.
@see Now(), wxGetUTCTimeMillis()
*/
static wxDateTime UNow();
};
/**
Global instance of an empty wxDateTime object.
@todo Would it be better to rename this wxNullDateTime so it's consistent
with the rest of the "empty/invalid/null" global objects?
*/
const wxDateTime wxDefaultDateTime;
/*
wxInvalidDateTime is an alias for wxDefaultDateTime.
*/
#define wxInvalidDateTime wxDefaultDateTime
/**
@class wxDateTimeWorkDays
@todo Write wxDateTimeWorkDays documentation.
@library{wxbase}
@category{data}
*/
class wxDateTimeWorkDays
{
public:
};
/**
@class wxDateSpan
This class is a "logical time span" and is useful for implementing program
logic for such things as "add one month to the date" which, in general,
doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
the next month (to understand that this is indeed different consider adding
one month to Feb, 15 -- we want to get Mar, 15, of course).
When adding a month to the date, all lesser components (days, hours, ...)
won't be changed unless the resulting date would be invalid: for example,
Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
Because of this feature, adding and subtracting back again the same
wxDateSpan will @b not, in general, give back the original date: Feb 28 - 1
month will be Jan 28, not Jan 31!
wxDateSpan objects can be either positive or negative. They may be
multiplied by scalars which multiply all deltas by the scalar: i.e.
2*(1 month and 1 day) is 2 months and 2 days. They can be added together
with wxDateTime or wxTimeSpan, but the type of result is different for each
case.
@warning If you specify both weeks and days, the total number of days added
will be 7*weeks + days! See also GetTotalDays().
Equality operators are defined for wxDateSpans. Two wxDateSpans are equal
if and only if they both give the same target date when added to @b every
source date. Thus wxDateSpan::Months(1) is not equal to
wxDateSpan::Days(30), because they don't give the same date when added to
Feb 1st. But wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2).
Finally, notice that for adding hours, minutes and so on you don't need
this class at all: wxTimeSpan will do the job because there are no
subtleties associated with those (we don't support leap seconds).
@library{wxbase}
@category{data}
@see @ref overview_datetime, wxDateTime
*/
class wxDateSpan
{
public:
/**
Constructs the date span object for the given number of years, months,
weeks and days. Note that the weeks and days add together if both are
given.
*/
wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0);
/**
Returns the sum of two date spans.
@return A new wxDateSpan object with the result.
*/
wxDateSpan Add(const wxDateSpan& other) const;
/**
Adds the given wxDateSpan to this wxDateSpan and returns a reference
to itself.
*/
wxDateSpan& Add(const wxDateSpan& other);
/**
Returns a date span object corresponding to one day.
@see Days()
*/
static wxDateSpan Day();
/**
Returns a date span object corresponding to the given number of days.
@see Day()
*/
static wxDateSpan Days(int days);
/**
Returns the number of days (not counting the weeks component) in this
date span.
@see GetTotalDays()
*/
int GetDays() const;
/**
Returns the number of the months (not counting the years) in this date
span.
*/
int GetMonths() const;
/**
Returns the combined number of months in this date span, counting both
years and months.
@see GetYears(), GetMonths()
@since 2.9.5
*/
int GetTotalMonths() const;
/**
Returns the combined number of days in this date span, counting both
weeks and days. This doesn't take months or years into account.
@see GetWeeks(), GetDays()
*/
int GetTotalDays() const;
/**
Returns the number of weeks in this date span.
@see GetTotalDays()
*/
int GetWeeks() const;
/**
Returns the number of years in this date span.
*/
int GetYears() const;
/**
Returns a date span object corresponding to one month.
@see Months()
*/
static wxDateSpan Month();
/**
Returns a date span object corresponding to the given number of months.
@see Month()
*/
static wxDateSpan Months(int mon);
/**
Returns the product of the date span by the specified @a factor. The
product is computed by multiplying each of the components by the
@a factor.
@return A new wxDateSpan object with the result.
*/
wxDateSpan Multiply(int factor) const;
/**
Multiplies this date span by the specified @a factor. The product is
computed by multiplying each of the components by the @a factor.
@return A reference to this wxDateSpan object modified in place.
*/
wxDateSpan& Multiply(int factor);
/**
Changes the sign of this date span.
@see Negate()
*/
wxDateSpan& Neg();
/**
Returns a date span with the opposite sign.
@see Neg()
*/
wxDateSpan Negate() const;
/**
Sets the number of days (without modifying any other components) in
this date span.
*/
wxDateSpan& SetDays(int n);
/**
Sets the number of months (without modifying any other components) in
this date span.
*/
wxDateSpan& SetMonths(int n);
/**
Sets the number of weeks (without modifying any other components) in
this date span.
*/
wxDateSpan& SetWeeks(int n);
/**
Sets the number of years (without modifying any other components) in
this date span.
*/
wxDateSpan& SetYears(int n);
/**
Returns the difference of two date spans.
@return A new wxDateSpan object with the result.
*/
wxDateSpan Subtract(const wxDateSpan& other) const;
/**
Subtracts the given wxDateSpan to this wxDateSpan and returns a
reference to itself.
*/
wxDateSpan& Subtract(const wxDateSpan& other);
/**
Returns a date span object corresponding to one week.
@see Weeks()
*/
static wxDateSpan Week();
/**
Returns a date span object corresponding to the given number of weeks.
@see Week()
*/
static wxDateSpan Weeks(int weeks);
/**
Returns a date span object corresponding to one year.
@see Years()
*/
static wxDateSpan Year();
/**
Returns a date span object corresponding to the given number of years.
@see Year()
*/
static wxDateSpan Years(int years);
/**
Adds the given wxDateSpan to this wxDateSpan and returns the result.
*/
wxDateSpan& operator+=(const wxDateSpan& other);
/**
Subtracts the given wxDateSpan to this wxDateSpan and returns the
result.
*/
wxDateSpan& operator-=(const wxDateSpan& other);
/**
Changes the sign of this date span.
@see Negate()
*/
wxDateSpan& operator-();
/**
Multiplies this date span by the specified @a factor. The product is
computed by multiplying each of the components by the @a factor.
@return A reference to this wxDateSpan object modified in place.
*/
wxDateSpan& operator*=(int factor);
/**
Returns @true if this date span is different from the other one.
*/
bool operator!=(const wxDateSpan& other) const;
/**
Returns @true if this date span is equal to the other one. Two date
spans are considered equal if and only if they have the same number of
years and months and the same total number of days (counting both days
and weeks).
*/
bool operator==(const wxDateSpan& other) const;
};
/**
@class wxTimeSpan
wxTimeSpan class represents a time interval.
@library{wxbase}
@category{data}
@see @ref overview_datetime, wxDateTime
*/
class wxTimeSpan
{
public:
/**
Default constructor, constructs a zero timespan.
*/
wxTimeSpan();
/**
Constructs timespan from separate values for each component, with the
date set to 0. Hours are not restricted to 0-24 range, neither are
minutes, seconds or milliseconds.
*/
wxTimeSpan(long hours, long min = 0, wxLongLong sec = 0, wxLongLong msec = 0);
/**
Returns the absolute value of the timespan: does not modify the object.
*/
wxTimeSpan Abs() const;
/**
Returns the sum of two time spans.
@return A new wxDateSpan object with the result.
*/
wxTimeSpan Add(const wxTimeSpan& diff) const;
/**
Adds the given wxTimeSpan to this wxTimeSpan and returns a reference
to itself.
*/
wxTimeSpan& Add(const wxTimeSpan& diff);
/**
Returns the timespan for one day.
*/
static wxTimeSpan Day();
/**
Returns the timespan for the given number of days.
*/
static wxTimeSpan Days(long days);
/**
Returns the string containing the formatted representation of the time
span. The following format specifiers are allowed after %:
- @c H - Number of Hours
- @c M - Number of Minutes
- @c S - Number of Seconds
- @c l - Number of Milliseconds
- @c D - Number of Days
- @c E - Number of Weeks
- @c % - The percent character
Note that, for example, the number of hours in the description above is
not well defined: it can be either the total number of hours (for
example, for a time span of 50 hours this would be 50) or just the hour
part of the time span, which would be 2 in this case as 50 hours is
equal to 2 days and 2 hours.
wxTimeSpan resolves this ambiguity in the following way: if there had
been, indeed, the @c %D format specified preceding the @c %H, then it
is interpreted as 2. Otherwise, it is 50.
The same applies to all other format specifiers: if they follow a
specifier of larger unit, only the rest part is taken, otherwise the
full value is used.
*/
wxString Format(const wxString& format = wxDefaultTimeSpanFormat) const;
/**
Returns the difference in number of days.
*/
int GetDays() const;
/**
Returns the difference in number of hours.
*/
int GetHours() const;
/**
Returns the difference in number of milliseconds.
*/
wxLongLong GetMilliseconds() const;
/**
Returns the difference in number of minutes.
*/
int GetMinutes() const;
/**
Returns the difference in number of seconds.
*/
wxLongLong GetSeconds() const;
/**
Returns the internal representation of timespan.
*/
wxLongLong GetValue() const;
/**
Returns the difference in number of weeks.
*/
int GetWeeks() const;
/**
Returns the timespan for one hour.
*/
static wxTimeSpan Hour();
/**
Returns the timespan for the given number of hours.
*/
static wxTimeSpan Hours(long hours);
/**
Returns @true if two timespans are equal.
*/
bool IsEqualTo(const wxTimeSpan& ts) const;
/**
Compares two timespans: works with the absolute values, i.e.\ -2 hours
is longer than 1 hour. Also, it will return @false if the timespans are
equal in absolute value.
*/
bool IsLongerThan(const wxTimeSpan& ts) const;
/**
Returns @true if the timespan is negative.
*/
bool IsNegative() const;
/**
Returns @true if the timespan is empty.
*/
bool IsNull() const;
/**
Returns @true if the timespan is positive.
*/
bool IsPositive() const;
/**
Compares two timespans: works with the absolute values, i.e.\ 1 hour is
shorter than -2 hours. Also, it will return @false if the timespans are
equal in absolute value.
*/
bool IsShorterThan(const wxTimeSpan& ts) const;
/**
Returns the timespan for one millisecond.
*/
static wxTimeSpan Millisecond();
/**
Returns the timespan for the given number of milliseconds.
*/
static wxTimeSpan Milliseconds(wxLongLong ms);
/**
Returns the timespan for one minute.
*/
static wxTimeSpan Minute();
/**
Returns the timespan for the given number of minutes.
*/
static wxTimeSpan Minutes(long min);
/**
Returns the product of this time span by @a n.
@return A new wxTimeSpan object with the result.
*/
wxTimeSpan Multiply(int n) const;
/**
Multiplies this time span by @a n.
@return A reference to this wxTimeSpan object modified in place.
*/
wxTimeSpan& Multiply(int n);
/**
Negate the value of the timespan.
@see Negate()
*/
wxTimeSpan& Neg();
/**
Returns timespan with inverted sign.
@see Neg()
*/
wxTimeSpan Negate() const;
/**
Returns the timespan for one second.
*/
static wxTimeSpan Second();
/**
Returns the timespan for the given number of seconds.
*/
static wxTimeSpan Seconds(wxLongLong sec);
/**
Returns the difference of two time spans.
@return A new wxDateSpan object with the result.
*/
wxTimeSpan Subtract(const wxTimeSpan& diff) const;
/**
Subtracts the given wxTimeSpan to this wxTimeSpan and returns a
reference to itself.
*/
wxTimeSpan& Subtract(const wxTimeSpan& diff);
/**
Returns the timespan for one week.
*/
static wxTimeSpan Week();
/**
Returns the timespan for the given number of weeks.
*/
static wxTimeSpan Weeks(long weeks);
/**
Adds the given wxTimeSpan to this wxTimeSpan and returns the result.
*/
wxTimeSpan& operator+=(const wxTimeSpan& diff);
/**
Multiplies this time span by @a n.
@return A reference to this wxTimeSpan object modified in place.
*/
wxTimeSpan& operator*=(int n);
/**
Negate the value of the timespan.
@see Negate()
*/
wxTimeSpan& operator-();
/**
Subtracts the given wxTimeSpan to this wxTimeSpan and returns the
result.
*/
wxTimeSpan& operator-=(const wxTimeSpan& diff);
};
/**
@class wxDateTimeHolidayAuthority
@todo Write wxDateTimeHolidayAuthority documentation.
@library{wxbase}
@category{data}
*/
class wxDateTimeHolidayAuthority
{
public:
};
|