Skip to content

Commit

Permalink
UTC Datetime inconsistency for LedgerPostings/Reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac-GC committed Jan 31, 2024
1 parent de2ae58 commit 9b2382a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion models/Transactional/LedgerPosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,28 @@ export class LedgerPosting {
return map[account];
}

// Timezone inconsistency fix (very ugly code for now)
let entryDateTime = this.refDoc.date as string | Date;
let dateTimeValue: Date;
if (typeof entryDateTime === 'string' || entryDateTime instanceof String) {
dateTimeValue = new Date(entryDateTime);
} else {
dateTimeValue = entryDateTime;
}
let dtFixedValue = dateTimeValue;
let dtMinutes = dtFixedValue.getTimezoneOffset() % 60;
let dtHours = (dtFixedValue.getTimezoneOffset() - dtMinutes) / 60;
dtFixedValue.setHours(dtFixedValue.getHours() - dtHours);
dtFixedValue.setMinutes(dtFixedValue.getMinutes() - dtMinutes);

// 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,
Expand Down

0 comments on commit 9b2382a

Please sign in to comment.