Commit Graph
152 Commits
Author SHA1 Message Date
dxbjavidandVadim Zeitlin 53901b80d2 Fix out-of-bounds read on trailing % in wxDateTime::Format()
Add a unit test but restrict it to only the cases when our own function
is used because MSVC CRT strftime() asserts in this case.

Closes #26543.
2026-06-04 17:19:27 +02:00
Vadim Zeitlin 3b01ebf5ef Add forgotten support for %T to our own wxDateTime::Format() code
"%T" was only handled when strftime() could be used but not by our own
implementation, resulting in failing to handle it for format string
including both "%T" and one of the specifiers not supported by the
standard function, such as "%l" or several others when using MinGW.

Closes #26179.
2026-02-10 14:08:58 +01:00
Vadim Zeitlin 2f15e8a5a3 Test for Apple platforms, not toolkits, in non-GUI tests
__WXOSX__ and __WXOSX_IPHONE__ don't need to be defined (although they
currently are) for non-GUI code.
2026-01-07 16:39:43 +01:00
Lauri NurmiandVadim Zeitlin 9bbb2dfb6b Test only one wxDateTimeHolidayAuthority at a time
wxDateTimeChristianHolidays was tested with a wxDateTimeUSCatholicFeasts
already existing and taking precedence. I.e. the tests for Christmas in
ChristianHolidays actually tested (again) the USCatholicFeasts
implementation.

This reveals an off-by-one bug in wxDateTimeChristianHolidays::DoIsHoliday(),
which doesn't use the enum symbol for month, and declares Christmas to be
on the 25th day of the 13th month.

Further, this raises the question whether it is a bad idea to have the
authority implementations in a header. Fixing bugs like this would
require recompiling the application, instead of simply updating the
DLL/dylib.
2025-08-30 15:05:40 +02:00
Lauri NurmiandVadim Zeitlin 6d8b1d4c14 Enable TestTimeTicks() for dates between 1970 and Y2K38
TestTimeTicks() checks were skipped for test dates with gmticks == -1,
ensure that these tests really run by providing the expected ticks
values.

See #24442.
2025-05-10 18:34:01 +02:00
Vadim Zeitlin 181b20b5b8 Restore support for years > 3000 in wxDateTime with MSVC CRT
Changes of a08c710b38 (Merge branch 'y2k38-fixes', 2024-04-14) broke
support for dates with year > 3000 when using MSVC CRT with 64-bit
time_t as it still doesn't support such dates even if they fit into the
type range.

Fix this by restoring the use of our own code instead of using CRT in
this case.

See #24464.

Closes #25228.
2025-03-10 18:56:27 +01:00
Vadim Zeitlin 2cc3a3814c Support padding format flags in wxDateTime::ParseFormat()
This is not really used when parsing, but we still need to support the
GNU extensions to the strftime() formatting specifiers used to change
padding, as they can (and do, at least in the case of "%-d" and "%-m")
occur in the locale descriptions and so can be used when parsing dates
using the current locale format.

Closes #24533.
2024-05-17 17:52:32 +02:00
Vadim Zeitlin 5c4e6deee8 Organize wxDateTime::ParseFormat() unit tests in sections
This allows to use REQUIRE() for the tests which must not fail for the
subsequent tests in the same section to succeed.
2024-05-17 17:37:20 +02:00
Vadim Zeitlin 63de901ccb Split wxDateTime::ParseFormat() tests in their own test case
It wasn't very logical to have them in the same test case as the tests
for wxDateTime::Format().

No real changes.
2024-05-17 17:37:20 +02:00
Vadim Zeitlin 3554d2ebb7 Get rid of CppUnit boilerplate in wxDateTime unit tests
Remove completely unnecessary DateTimeTestCase and use CHECK() instead
of CppUnit macros.
2024-05-17 17:37:20 +02:00
Lauri NurmiandVadim Zeitlin 52cd3aeb5b Use wxInt64 instead of time_t for gmticks of testDates
This allows successfully running the tests with dates beyond Y2K38,
when time_t is 32-bit.
2024-04-14 16:51:57 +02:00
Lauri NurmiandVadim Zeitlin 5b75a347da Add a test date beyond Y2K38 but within this century 2024-04-14 16:51:57 +02:00
Vadim Zeitlin 8f379f28a9 Remove tags from the hidden wxDateTime BST test
This test shouldn't run when "[datetime]" or another tag is specified on
the command line as it always fails in non-BST time zone, so only run it
if it's explicitly selected by name.
2024-04-08 15:08:04 +02:00
Vadim Zeitlin 7543e49c3c Add support for %F (ISO 8601 date) format specifier to wxDateTime
Recognize it when formatting and parsing dates.

Closes #24173.
2023-12-30 17:01:19 +01:00
Blake-MaddenandVadim Zeitlin 5ba009e861 Add Catholic Feasts holiday authority class (US observances)
This includes a static function to calculate Easter that can be used for
other authorities.

Document the wxDateTimeWorkDays and wxDateTimeHolidayAuthority classes.

Closes #24094.
2023-12-05 00:53:26 +01:00
Blake-MaddenandVadim Zeitlin fc9e188116 Handle 'T' separator in wxDateTime::ParseDateTime()
ParseDateTime() currently fails if there is a 'T' separator in front of
time component. FormatISOCombined() uses this separator as the default,
so wxDateTime can't parse its own formatted results by default.

This commit fixes that issue by allowing an optional 'T' between the
date and time parts.

Closes #22999.
2022-11-30 02:23:37 +01:00
Vadim Zeitlin 4519d8e08a Remove wxUSE_UNICODE checks as they're always true now
Also remove all code guarded by "#if !wxUSE_UNICODE".
2022-10-27 19:43:30 +02:00
Vadim Zeitlin 4f4c5fcfdf Use nullptr instead of NULL in the code and documentation
This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.

Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.

And also use null in the assert messages.

Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
2022-10-18 01:25:25 +02:00
Vadim Zeitlin f280bcdb58 Improve error reporting in wxDateTime unit tests
Simply use INFO() to give all the information we want to see in case of
failure once instead of doing it in multiple WX_ASSERT_MESSAGE() in a
more ugly way with extra parentheses.

Also use FAIL_CHECK() to keep running the test after the first failure.
2022-03-28 00:56:19 +02:00
Lauri Nurmi fdd05c8b8b Parse also time zone in ParseDateTime(), if found
Accept the same kind of time zone specifiers that RFC822 timestamps
accept; most importantly the "+0200" style.

Added more tests, and changed the way tests compare dates:
Since some timestamps now specify a time zone, those need to be compared
as UTC to avoid the system's time zone affecting the tests. Others can
still be compared as local time, as before.
2022-03-22 19:12:48 +02:00
Lauri Nurmi 770cf26afe Fix out-of-bounds with military and truncated time zones; add more tests
Out-of-bounds was already covered by the fact that the date is appended 32
zero-bytes in ParseRFC822Date() as a safety measure. But now the time zone
parsing section of the function no longer relies on those extra zeros
being present.

Added tests for RFC822 timestamps with military time zones, and more types
of truncated, invalid time zone specifiers.
2022-03-22 19:11:22 +02:00
Lauri Nurmi 89eec3cb80 Fix truncated time zone specifier tests for ParseRFC822Date()
Correction to the commit:
2153ffc (Test ParseRFC822Date() with truncated time zone specifiers,
2022-03-19)

The inputs failed as expected, but due to an unrelated reason (missing
comma).
2022-03-22 19:09:23 +02:00
Lauri NurmiandVadim Zeitlin 088e643d37 Do not consume whitespace/delimiters after date in DateParse()
Set the end iterator to the end of the actually parsed date, instead
of consuming any ultimately unparsed whitespace/delimiters possibly
following the date.
2022-03-19 22:56:08 +01:00
Lauri NurmiandVadim Zeitlin 945738042d Fix ParseDate() for dates having day expressed as an ordinal
Previously the year was left unparsed, and the current year was
incorrectly used even when the input provided a year.
2022-03-19 22:56:08 +01:00
Lauri NurmiandVadim Zeitlin 700d763ebc Test ParseDate() with dates containing a weekday
Test both a weekday that matches the date, and one that does not.
2022-03-19 22:56:08 +01:00
Lauri NurmiandVadim Zeitlin 4cf335340c Test the end iterator set by Parse{Date,Time,DateTime}()
In other words, check that the unprocessed part of the input is what
we expected.

Also add some cases where a valid date or time is followed by something.
2022-03-19 22:56:07 +01:00
Lauri NurmiandVadim Zeitlin 23b8ec6d9a Test ParseRFC822Date() with truncated time zone specifiers 2022-03-19 22:56:07 +01:00
Lauri NurmiandVadim Zeitlin 504c0b16c3 Fix ParseDateTime() to also accept time + date, in that order
The intent of the implementation clearly is to allow parsing time first,
date second. But this failed, because a time such as "14:30:15" would
successfully parse as a date (as 14th of current month, current year).

Consequently an attempt is made to parse the actual date as time, which
fails, and therefore the whole ParseDateTime() fails.

Adding a failing test case for ensuring times cannot be parsed as dates
does not cause a failure, because partially yet successfully parsed inputs
get silently ignored (in both ParseDate and ParseDateTime tests). Fixing
both of these, too.

Closes #22203.
2022-03-18 00:01:18 +01:00
Lauri NurmiandVadim Zeitlin 538a75fe4e Decode 2-digit years properly in ParseRfc822Date()
The RFC accepts 2-digit years, and it makes most sense to interpret
e.g. 95 as 1995. However, this is an incompatible change, as earlier
95 was literally decoded as 95 AD.

Years 00..29 are considered to mean 20xx; 30..99 means 19xx.

Closes #22196.
2022-03-17 23:55:57 +01:00
Lauri Nurmi 1c5e66a12c Allow RFC822 timestamps without a week day
RFC 822 specifies the week day is optional.
2022-03-10 19:25:21 +02:00
Lauri NurmiandVadim Zeitlin 8d9d2684ef Fix out-of-bounds reads in ParseRfc822Date() with too short input
The implementation implicitly relies, in many places, on the assumption
that the input never ends prematurely. If it does, the iterator
pointing beyond the end of buffer is dereferenced, which is UB.

The solution used here is to append 32 zero bytes to the date string,
which hopefully keeps the code more readable than checking for the end
of string before each deference operation.

Add various syntactically invalid inputs to unit tests.

Closes #22185.
2022-03-10 16:44:44 +01:00
Vadim Zeitlin a4940bf696 Extract wxLocaleSetter from the tests into a private header
This will allow using this class in the library code too.

No real changes yet, this is a pure refactoring.

This commit is best viewed using git --color-moved option.
2021-08-07 18:04:22 +02:00
Paul Cornett c82e13068a Fix comment typo 2021-03-17 10:30:34 -07:00
PB f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Vadim Zeitlin 3ab187f75f Add a test for "%e" to wxDateTime::ParseFormat()
See https://github.com/wxWidgets/wxWidgets/pull/1842
2020-05-09 23:23:31 +02:00
Vadim Zeitlin 2cf0537722 Correct the test for ParseFormat() with fall back date
This was added back in b5f85206a9 (fix ParseFormat("%d") to set the date
it finds (#10002), 2008-09-26), but the test didn't do what the comment
said and didn't use the default date object it added.

Fix this now to finally do what was intended all these years ago.
2020-05-09 23:22:13 +02:00
Vadim Zeitlin c26353f13f Add another workaround for failures in wxDateTime::UNow test
If current time doesn't have the milliseconds parts, we need to sleep
for a little before retrying.
2019-11-13 15:39:36 +01:00
Vadim Zeitlin 1b063e1dea Add a delay before calling wxDateTime::UNow() again in the test
Retrying immediately wasn't very useful, as the times must have been the
same during all loop iterations anyhow, so add a sleep to try to finally
fix the sporadic test failure on Travis.
2019-10-23 11:43:53 +02:00
Vadim Zeitlin 3d488ef8a3 Replace INFO() with WARN() in wxDateTime::UNow() unit test
Another desperate attempt to understand how are failures such as the one
at https://travis-ci.org/wxWidgets/wxWidgets/jobs/601043830 possible.
2019-10-22 15:12:39 +02:00
Vadim Zeitlin 8d962b0121 Add a diagnostic message to wxDateTime::UNow() unit test
Try to understand what's going in Travis CI builds.
2019-10-19 23:05:32 +02:00
Vadim Zeitlin c4e914784a Guard against Now() and UNow() returning different second values
Avoid spurious error in the unit test by calling Now() and UNow() a few
times in a row until they return the same second, as we may be unlucky
enough for this not to be the case when we call them just once.
2019-10-19 20:02:42 +02:00
Vadim Zeitlin c92f9e0a17 Document that wxDateTime::UNow() returns time in local time zone
This is its actual behaviour and it's the right thing to do, as it's
consistent with Now() -- even though the documentation wrongly stated
otherwise (since 324ab5e2db).

Also add a unit test checking that UNow() == Now(), except for the
milliseconds.

See #14148.

Closes #18524.

Closes https://github.com/wxWidgets/wxWidgets/pull/1594
2019-10-07 12:27:28 +02:00
Vadim Zeitlin 5488a1438f Globally replace vadim@wxwindows.org with vadim@wxwidgets.org
The old email address is invalid since many years and shouldn't be used
any longer.

No real changes.
2019-04-22 14:12:05 +02:00
Vadim Zeitlin 2a907769fb Suppress all -Wmissing-field-initializers in the test suite
There were many dozens of such warnings given for the various arrays
used in the tests and it just doesn't seem feasible nor desirable to fix
them all, so just suppress the warnings for all these arrays to get rid
of them with recent (7+?) versions of gcc.
2019-02-02 17:25:37 +01:00
Vadim Zeitlin 15a97924b6 Simplify wxDateTime ticks test by only using UTC times
Converting to another time zone and dealing with DST is completely
useless here, ticks values are always in UTC, so we can just use UTC
values from the beginning.
2017-12-02 14:38:45 +01:00
Vadim Zeitlin 179dced0e0 Include testdate.h before catch.hpp in unit tests
This ensures that dates are printed out correctly if comparing them
fails.

It might be better to avoid always including this header, but this is
the simplest solution.
2017-12-02 14:38:19 +01:00
Vadim Zeitlin 322144299d Use wxDateTime::TimeZone::IsLocal() in the unit test
No real changes, as this doesn't affect this test, but use the new
IsLocal() method instead of comparing the time zone offset with the time
zone, which doesn't work correctly for BST.
2017-11-30 17:53:52 +01:00
Vadim Zeitlin d49784b0a2 Disable wxDateTime tests failing due to TZ offset changes
wxDateTime timezone-related methods always use the current timezone
offset, while other methods, using CRT, use correct value for the given
date, which may be different.

This discrepancy accounted for test failures in Europe/Minsk time zone
as Belarus has switched from UTC+2 to UTC+3 since 1999 date used in the
test.

It is impossible to really fix the problem easily, so just skip the test
in this case and also mention this bug in the documentation.

See #15370.
2017-11-30 17:44:41 +01:00
Vadim Zeitlin d3a01e3fe6 Show more information in other DateTimeTestCase tests too
Show the loop variable when doing checks inside a loop to make it more
obvious for which test case the failures occur.

Also use CHECK(), instead of REQUIRE(), to which CPPUNIT_ASSERT_EQUAL
expands, to continue with the other loop iterations after failure.
2017-11-29 23:55:13 +01:00
Vadim Zeitlin 4868ec0893 Show more information if DateTimeTestCase::TestTimeFormat() fails
No real changes, just show the variable values if any checks fail and
also continue running the test for the other data points even if one of
them fails.
2017-11-29 23:19:01 +01:00