Skip to content
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

Fixes issue #585 ( bug in io.timestamp2datetime ) #586

Merged
merged 3 commits into from
Sep 10, 2024

Conversation

ehennestad
Copy link
Collaborator

@ehennestad ehennestad commented Sep 3, 2024

Fix #585 ( bug in io.timestamp2datetime )

Some dates were assigned wrongly when Day, Month and Year are set individually, as the datetime object internally/silently adjusts month if day is not valid

Motivation

What was the reasoning behind this change? Please explain the changes briefly.

How to test the behavior?

Show here how to reproduce the new behavior (can be a bug fix or a new feature)

Checklist

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

Some dates are assigned wrongly when Day, Month and Year are set individually, as the datetime object internally/silently adjusts month if day is not valid
Fix: Should not preallocate datetimeArray as it is not known beforehand whether the timestamp has a timezone or not (datetime.empty contrains to datetime w/o timezone)
@bendichter
Copy link
Contributor

Looks great! Could you add a check demonstrating that the bug you found earlier is fixed?

@ehennestad
Copy link
Collaborator Author

NWBDefaultStringFormat = "uuuu-MM-dd'T'HH:mm:ss.SSSSSSZZZZZ";

testDate = datetime(2024, 8, 31, 'TimeZone', 'local'); % Start date: January 1st
testDate.Format = NWBDefaultStringFormat;
testDateAsString = string(testDate);

io.timestamp2datetime(testDateAsString)

ans = 

  datetime

   31-Aug-2024

I will also be adding a unittest in another PR that test all dates for a complete calendar year

@bendichter
Copy link
Contributor

Could you include the test in this PR? That's how we generally package PRs.

Add unit test for io.timestamp2datetime function
@bendichter
Copy link
Contributor

@ehennestad Generally, the tests should include a snippet of code that failed previously and passes now. There are a lot of tests here now but I don't think I see the specific failure mode you mentioned in the bug report here.

@bendichter bendichter merged commit 904ff14 into master Sep 10, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: io.timestamp2datetime does not work for some edgecase dates
2 participants