-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix DueDate.StringDate conversion to and from DateTime. #37
Conversation
The class is used to change the time zone of the tests upon initialization, and resets it back when disposed.
The added tests ensure consistency in StringDate property setter and getter.
Date is now converted using the round-trip format without milliseconds. Date is also no longer being converted to universal time before formatting.
DateTimeKind is switched to Unspecified instead of Utc since the due date should be treated as floating.
Kudos, SonarCloud Quality Gate passed!
|
Thank you for your contribution! 👍🏻 |
@AhmedZaki99 todoist-net/src/Todoist.Net.Tests/Services/ItemsServiceTests.cs Lines 186 to 199 in 2a0bead
I should have run the test before merging the PR, my bad. Please open a new PR with fixes. |
Fixes #36
First, existing unit tests for the
DueDate
model should be modified to run on different time zones to ensure that date conversion works correctly no matter where it runs.That's why on the first commit, a
FakeLocalTimeZone
helper class is added to mimic different time zones for tests when necessary (see this SO question for more details), which is used with theDueDate
model tests to randomize the time zone in which tests are run.Second, additional tests are added for the
DueDate
model to test the date conversion in theStringDate
property getter and setter, which fail as expected.Last, the
StringDate
toDate
conversion process has been modified to use theDateTimeStyles.RoundtripKind
with theDateTime.Parse
method. Then when converting back, the round-trip format is used instead of the sortable-date format, with the exclusion of milliseconds.Note: The
DueDate
floating date assignment unit test has been modified to use a date withDateTimeKind.Unspecified
instead ofDateTimeKind.Utc
since floating dates are treated now as non-UTC dates.