diff --git a/models/Transactional/LedgerPosting.ts b/models/Transactional/LedgerPosting.ts index b342a0ce..cbc791f8 100644 --- a/models/Transactional/LedgerPosting.ts +++ b/models/Transactional/LedgerPosting.ts @@ -61,6 +61,21 @@ export class LedgerPosting { this._validateIsEqual(); } + timezoneDateTimeAdjuster(setDate: string | Date) { + const dateTimeValue = new Date(setDate); + + 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); + + return dtFixedValue; + } + async makeRoundOffEntry() { const { debit, credit } = this._getTotalDebitAndCredit(); const difference = debit.sub(credit); @@ -90,23 +105,6 @@ 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) { - 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( @@ -114,7 +112,7 @@ export class LedgerPosting { { account: account, party: (this.refDoc.party as string) ?? '', - date: dtFixedValue, + date: this.timezoneDateTimeAdjuster(this.refDoc.date as string | Date), referenceType: this.refDoc.schemaName, referenceName: this.refDoc.name!, reverted: this.reverted,