-
Notifications
You must be signed in to change notification settings - Fork 688
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
**/types.ts | ||
**/dist_electron | ||
**/dummy/*.json | ||
**/.github/ISSUE_TEMPLATE/*.yml | ||
**/.github/ISSUE_TEMPLATE/*.yml | ||
**/patches/v0_21_0/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { DatabaseManager } from '../../database/manager'; | ||
|
||
/* eslint-disable */ | ||
async function execute(dm: DatabaseManager) { | ||
await dm.db!.knex!('AccountingLedgerEntry') | ||
.select('name', 'date') | ||
.then((trx: Array<{name: string; date: Date;}> ) => { | ||
trx.forEach(async entry => { | ||
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); | ||
entryDate.setSeconds(0); | ||
entryDate.setMilliseconds(0); | ||
|
||
await dm.db!.knex!('AccountingLedgerEntry') | ||
.where({ name: entry['name'] }) | ||
.update({ date: entryDate.toISOString() }); | ||
}); | ||
}); | ||
} | ||
|
||
export default { execute, beforeMigrate: true }; | ||
/* eslint-enable */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,12 +90,31 @@ export class LedgerPosting { | |
return map[account]; | ||
} | ||
|
||
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that equivalent? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
dateTimeValue = new Date(entryDateTime); | ||
} else { | ||
dateTimeValue = entryDateTime; | ||
} | ||
const dtFixedValue = dateTimeValue; | ||
const dtMinutes = dtFixedValue.getTimezoneOffset() % 60; | ||
const dtHours = (dtFixedValue.getTimezoneOffset() - dtMinutes) / 60; | ||
// Forcing the time to always be set to 00:00.000 for locale time | ||
dtFixedValue.setHours(0 - dtHours); | ||
dtFixedValue.setMinutes(0 - dtMinutes); | ||
dtFixedValue.setSeconds(0); | ||
dtFixedValue.setMilliseconds(0); | ||
|
||
// end ugly timezone fix code | ||
|
||
const ledgerEntry = this.fyo.doc.getNewDoc( | ||
ModelNameEnum.AccountingLedgerEntry, | ||
{ | ||
account: account, | ||
party: (this.refDoc.party as string) ?? '', | ||
date: this.refDoc.date as string | Date, | ||
date: dtFixedValue, | ||
referenceType: this.refDoc.schemaName, | ||
referenceName: this.refDoc.name!, | ||
reverted: this.reverted, | ||
|
There was a problem hiding this comment.
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