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

Bug fix recorddate inconsistency #831

Merged
merged 2 commits into from Feb 2, 2024
Merged

Conversation

Isaac-GC
Copy link
Collaborator

After doing some testing in various timezones it looks like this (very ugly) patch successfully fixes the various timestamp inconsistency issues, which resulted in incorrect ledgers, profit/loss, etc

What was happening is that depending on one's timezone, the Date that was saved in the JournalEntry/Ledger would convert the Datetime to a timestamp of 00:00.000 for the local timezone and then calculates the GMT timestamp based on the local timezone. This creates an instance where what is saved may not properly reflect what was entered and expected in the related invoices (or other items).

Here are two test cases showing the issue of what was happening:

  1. Test case 1 (Myanmar timezone -> GMT +6.5)
image

The time is converted to GMT which is 6.5 hours behind Myanmar at that point of time, resulting in saving the datetime as previous date (in this test case, 2022-12-31T17:30.000Z)


  1. Test case 2 (US Pacific timezone -> GMT -8)
Screenshot 2024-01-30 193727

In this case, when the timestamp for the local timezone is 00:00.000, GMT time will be 8 hours ahead (2023-01-01T08:00.000Z)

Copy link
Contributor

@mildred mildred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. perhaps this could be in a separate function so its scope, input and output is more clearly understood.

// Timezone inconsistency fix (very ugly code for now)
const entryDateTime = this.refDoc.date as string | Date;
let dateTimeValue: Date;
if (typeof entryDateTime === 'string' || entryDateTime instanceof String) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that equivalent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be, yet as we saw with this DateTime fun, there are some weird errors that pop up. By forcing a check I want to make sure that it is as expected as I really don't want to revisit this error later.

@Isaac-GC
Copy link
Collaborator Author

Isaac-GC commented Feb 1, 2024

The plan is to break it out in the future, but as you mentioned we should check the scope of the entirety of the issue. I included it in the function to ensure its scope is only applied to that section and children that use it.

For the scope of the issue, if you look at the db patch, it shows all of the models affected

@Isaac-GC Isaac-GC force-pushed the bug_fix_recorddate_inconsistency branch from f048880 to ca2a316 Compare February 1, 2024 22:53
Comment on lines +9 to +22
const entryDate = new Date(entry['date']);
const timeZoneOffset = entryDate.getTimezoneOffset();
const offsetMinutes = timeZoneOffset % 60;
const offsetHours = (timeZoneOffset - offsetMinutes) / 60;

let daysToAdd = 0; // If behind or at GMT/Zulu time, don't need to add a day
if (timeZoneOffset < 0) {
// If ahead of GMT/Zulu time, need to advance a day forward first
daysToAdd = 1;
}

entryDate.setDate(entryDate.getDate() + daysToAdd);
entryDate.setHours(0 - offsetHours);
entryDate.setMinutes(0 - offsetMinutes);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the offsetMinutes and offsetHours to set the values aren't necessary but are there to mirror with the code fix in LedgerPosting.ts

@Isaac-GC Isaac-GC force-pushed the bug_fix_recorddate_inconsistency branch from 0f36a16 to 64ad73b Compare February 1, 2024 23:55
@Isaac-GC Isaac-GC merged commit 8db453c into master Feb 2, 2024
4 checks passed
@Isaac-GC Isaac-GC deleted the bug_fix_recorddate_inconsistency branch February 2, 2024 00:02
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.

None yet

2 participants