From ca871a80215bd31bc714ac2eae20dbda8eb442aa Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Mon, 17 Jun 2019 14:37:10 -0400 Subject: [PATCH 1/8] wip --- package-lock.json | 16 ++++ package.json | 2 + src/app/reports/balancesheet.ts | 4 +- src/app/reports/income.ts | 12 ++- src/app/shared/util.ts | 127 +++++++++++++++++++++++++++++--- src/app/transaction/list.ts | 21 +----- 6 files changed, 143 insertions(+), 39 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3f8ff3b..00e509b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -595,6 +595,14 @@ "@types/jasmine": "*" } }, + "@types/moment-timezone": { + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/@types/moment-timezone/-/moment-timezone-0.5.12.tgz", + "integrity": "sha512-hnHH2+Efg2vExr/dSz+IX860nSiyk9Sk4pJF2EmS11lRpMcNXeB4KBW5xcgw2QPsb9amTXdsVNEe5IoJXiT0uw==", + "requires": { + "moment": ">=2.14.0" + } + }, "@types/node": { "version": "8.9.5", "resolved": "http://registry.npmjs.org/@types/node/-/node-8.9.5.tgz", @@ -6408,6 +6416,14 @@ "minimist": "0.0.8" } }, + "moment-timezone": { + "version": "0.5.25", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.25.tgz", + "integrity": "sha512-DgEaTyN/z0HFaVcVbSyVCUU6HeFdnNC3vE4c9cgu2dgMTvjBUBdBzWfasTBmAW45u5OIMeCJtU8yNjM22DHucw==", + "requires": { + "moment": ">= 2.9.0" + } + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", diff --git a/package.json b/package.json index d55366f..3befa66 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,10 @@ "@angular/platform-browser-dynamic": "^6.1.0", "@angular/router": "^6.1.0", "@ng-bootstrap/ng-bootstrap": "^3.3.1", + "@types/moment-timezone": "^0.5.12", "bootstrap": "^4.1.3", "core-js": "^2.5.4", + "moment-timezone": "^0.5.25", "rxjs": "~6.2.0", "rxjs-compat": "6.0.0", "zone.js": "~0.8.26" diff --git a/src/app/reports/balancesheet.ts b/src/app/reports/balancesheet.ts index a8e40db..c03713c 100644 --- a/src/app/reports/balancesheet.ts +++ b/src/app/reports/balancesheet.ts @@ -63,7 +63,7 @@ export class BalanceSheetReport { } this.form = fb.group({ - date: [Util.getLocalDateString(this.date), Validators.required], + date: [Util.getLocalDateStringExcl(this.date), Validators.required], priceSource: [this.priceSource, Validators.required] }); } @@ -133,7 +133,7 @@ export class BalanceSheetReport { this.treeSubscription.unsubscribe(); //this.dataService.setLoading(true); this.showOptionsForm = false; - this.date = Util.getDateFromLocalDateString(this.form.value.date); + this.date = Util.getDateFromLocalDateStringExcl(this.form.value.date); this.priceSource = this.form.value.priceSource; let reportData = this.configService.get('reportData'); diff --git a/src/app/reports/income.ts b/src/app/reports/income.ts index cc614b8..2739a56 100644 --- a/src/app/reports/income.ts +++ b/src/app/reports/income.ts @@ -45,10 +45,9 @@ export class IncomeReport { private configService: ConfigService, private sessionService: SessionService) { this.startDate = new Date(); - this.startDate.setDate(1); - this.startDate.setHours(0, 0, 0, 0); - this.endDate = new Date(this.startDate); - this.endDate.setMonth(this.startDate.getMonth() + 1); + Util.setFirstOfMonth(this.startDate); + Util.setBeginOfDay(this.startDate); + this.endDate = Util.getOneMonthLater(this.startDate); let reportData = this.configService.get('reportData'); @@ -65,7 +64,7 @@ export class IncomeReport { this.form = fb.group({ startDate: [Util.getLocalDateString(this.startDate), Validators.required], - endDate: [Util.getLocalDateString(new Date(this.endDate.getTime() - 1)), Validators.required] + endDate: [Util.getLocalDateStringExcl(this.endDate), Validators.required] }); } @@ -92,8 +91,7 @@ export class IncomeReport { //this.dataService.setLoading(true); this.showDateForm = false; this.startDate = Util.getDateFromLocalDateString(this.form.value.startDate); - this.endDate = Util.getDateFromLocalDateString(this.form.value.endDate); - this.endDate.setDate(this.endDate.getDate() + 1); + this.endDate = Util.getDateFromLocalDateStringExcl(this.form.value.endDate); let reportData = this.configService.get('reportData'); diff --git a/src/app/shared/util.ts b/src/app/shared/util.ts index 57ca01e..1dba80f 100644 --- a/src/app/shared/util.ts +++ b/src/app/shared/util.ts @@ -1,8 +1,15 @@ +//import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'; +import * as moment from 'moment-timezone'; + +const defaultTz = moment.tz.guess(); + export class Util { - static getLocalDateString(input: Date) { - let year = input.getFullYear().toString(); - let month = (input.getMonth() + 1).toString(); - let date = input.getDate().toString(); + static getLocalDateString(input: Date, tz: string = defaultTz) { + let m = moment(input).tz(tz); + + let year = m.format('YYYY'); + let month = m.format('MM'); + let date = m.format('DD'); if(month.length < 2) { month = '0' + month; @@ -15,14 +22,112 @@ export class Util { return year + '-' + month + '-' + date; } - static getDateFromLocalDateString(input: string) { - let parts = input.split('-'); - let date = new Date(); - date.setHours(0, 0, 0, 0); - date.setFullYear(parseInt(parts[0])); - date.setMonth(parseInt(parts[1]) - 1, parseInt(parts[2])); + static getLocalDateStringExcl(input: Date, tz: string = defaultTz) { + let m = moment(input.getTime() - 1).tz(tz); - return date; + let year = m.format('YYYY'); + let month = m.format('MM'); + let date = m.format('DD'); + + if(month.length < 2) { + month = '0' + month; + } + + if(date.length < 2) { + date = '0' + date; + } + + return year + '-' + month + '-' + date; + } + + static getDateFromLocalDateString(input: string, tz: string = defaultTz) { + let parts = input.split('-'); + + let m = moment().tz(tz); + m.hours(0); + m.minutes(0); + m.seconds(0); + m.milliseconds(0); + m.year(parseInt(parts[0])); + m.month(parseInt(parts[1]) - 1); + m.date(parseInt(parts[2])); + + return m.toDate(); + } + + static getDateFromLocalDateStringExcl(input: string, tz: string = defaultTz) { + let parts = input.split('-'); + + let m = moment().tz(tz); + m.hours(0); + m.minutes(0); + m.seconds(0); + m.milliseconds(0); + m.year(parseInt(parts[0])); + m.month(parseInt(parts[1]) - 1); + m.date(parseInt(parts[2]) + 1); + + return m.toDate(); + } + + static setFirstOfMonth(input: Date, tz: string = defaultTz) { + let m = moment(input).tz(tz); + + m.date(1); + input.setTime(m.valueOf()); + } + + static setBeginOfDay(input: Date, tz: string = defaultTz) { + let m = moment(input).tz(tz); + + m.hours(0); + m.minutes(0); + m.seconds(0); + m.milliseconds(0); + input.setTime(m.valueOf()); + } + + static setEndOfDay(input: Date, tz: string = defaultTz) { + let m = moment(input).tz(tz); + + m.hours(23); + m.minutes(59); + m.seconds(59); + m.milliseconds(999); + input.setTime(m.valueOf()); + } + + static getOneMonthLater(input: Date, tz: string = defaultTz): Date { + let m = moment(input).tz(tz); + + m.month(m.month() + 1); + + return m.toDate(); + } + + static computeTransactionDate(formDate: Date, txDate: Date, tz: string = defaultTz): Date { + if(!formDate || !formDate.getTime()) { + return txDate; + } + + let formMoment = moment(formDate).tz(tz); + let txMoment = moment(txDate).tz(tz); + + // make the time be at the very end of the day + formMoment.hours(23); + formMoment.minutes(59); + formMoment.seconds(59); + formMoment.milliseconds(999); + + let sameDay = formMoment.year() === txMoment.year() && + formMoment.month() === txMoment.month() && + formMoment.date() === txMoment.date(); + + if(!sameDay) { + return formMoment.toDate(); + } + + return txDate; } static newGuid() { diff --git a/src/app/transaction/list.ts b/src/app/transaction/list.ts index 0d2db3d..d0fa5d7 100644 --- a/src/app/transaction/list.ts +++ b/src/app/transaction/list.ts @@ -624,7 +624,7 @@ export class TxListPage implements OnInit, AfterViewChecked { let date = item.tx.id ? item.tx.date : new Date(); let formDate = Util.getDateFromLocalDateString(item.form.value.date); - date = this.computeTransactionDate(formDate, date); + date = Util.computeTransactionDate(formDate, date); let tx = new Transaction({ id: item.tx.id, @@ -731,23 +731,6 @@ export class TxListPage implements OnInit, AfterViewChecked { } } - computeTransactionDate(formDate: Date, txDate: Date): Date { - if(formDate.getTime()) { - // make the time be at the very end of the day - formDate.setHours(23, 59, 59, 999); - } - - let sameDay = formDate.getFullYear() === txDate.getFullYear() && - formDate.getMonth() === txDate.getMonth() && - formDate.getDate() === txDate.getDate(); - - if(formDate.getTime() && !sameDay) { - txDate = formDate; - } - - return txDate; - } - deleteTransaction(item) { this.modalService.open(this.confirmDeleteModal).result.then((result) => { this.log.debug('delete'); @@ -846,7 +829,7 @@ export class TxListPage implements OnInit, AfterViewChecked { item.tx = new Transaction( { id: item.tx.id, - date: this.computeTransactionDate(formDate, new Date()), + date: Util.computeTransactionDate(formDate, new Date()), description: tx.description, splits: tx.splits } From b602cb174071f42d7d61903b1c2a0a0757f30a5c Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 27 Jun 2019 14:11:05 -0400 Subject: [PATCH 2/8] use timezone everywhere --- src/app/core/account.service.ts | 7 --- src/app/dashboard/dashboard.html | 2 +- src/app/dashboard/dashboard.ts | 4 +- src/app/price/price-modal.ts | 22 ++++---- src/app/price/pricedb.html | 2 +- src/app/reconcile/reconcile-modal.html | 4 +- src/app/reconcile/reconcile-modal.ts | 5 +- src/app/reconcile/reconcile.html | 2 +- src/app/reconcile/reconcile.ts | 16 +++--- src/app/reports/balancesheet.html | 2 +- src/app/reports/balancesheet.ts | 7 ++- src/app/reports/income.html | 2 +- src/app/reports/income.ts | 27 ++++----- src/app/shared/datetz.pipe.ts | 14 +++++ src/app/shared/org.ts | 2 + src/app/shared/shared.module.ts | 5 +- src/app/shared/util.ts | 78 ++++++++++++++++++-------- src/app/transaction/advancededit.ts | 17 +----- src/app/transaction/list.html | 2 +- src/app/transaction/list.ts | 21 ++++--- src/app/transaction/new.ts | 23 ++------ 21 files changed, 150 insertions(+), 114 deletions(-) create mode 100644 src/app/shared/datetz.pipe.ts diff --git a/src/app/core/account.service.ts b/src/app/core/account.service.ts index 0c70e94..b313dc1 100644 --- a/src/app/core/account.service.ts +++ b/src/app/core/account.service.ts @@ -590,13 +590,6 @@ export class AccountService { return this.apiService.deleteAccount(id); } - getPeriodStart(): Date { - let date = new Date(); - date.setDate(1); - date.setHours(0, 0, 0, 0); - return date; - } - createDefaultAccounts(tree: AccountTree): Observable { let assetAccount = tree.getAccountByName('Assets', 1); let equityAccount = tree.getAccountByName('Equity', 1); diff --git a/src/app/dashboard/dashboard.html b/src/app/dashboard/dashboard.html index aa10f7b..26eb95a 100644 --- a/src/app/dashboard/dashboard.html +++ b/src/app/dashboard/dashboard.html @@ -56,7 +56,7 @@
- {{recentTx.tx.date | date:"M/d"}} + {{recentTx.tx.date | datetz:"M/D":org.timezone}}
{{recentTx.tx.description}} diff --git a/src/app/dashboard/dashboard.ts b/src/app/dashboard/dashboard.ts index d669570..0e89728 100644 --- a/src/app/dashboard/dashboard.ts +++ b/src/app/dashboard/dashboard.ts @@ -7,6 +7,7 @@ import { SessionService } from '../core/session.service'; import { Transaction, Split } from '../shared/transaction'; import { Org } from '../shared/org'; import { Account, AccountTree } from '../shared/account'; +import { Util } from '../shared/util'; import { TxListPage } from '../transaction/list'; import { IncomeReport } from '../reports/income'; import { Observable } from 'rxjs/Observable'; @@ -46,11 +47,12 @@ export class DashboardPage implements OnInit { ngOnInit() { this.sessionService.setLoading(true); this.log.debug('dashboard init'); - let periodStart = this.accountService.getPeriodStart(); this.org = this.orgService.getCurrentOrg(); this.log.debug('org', this.org); + let periodStart = Util.getPeriodStart(this.org.timezone); + let tree$ = this.accountService.getAccountTreeWithPeriodBalance(periodStart); tree$.do(tree => { diff --git a/src/app/price/price-modal.ts b/src/app/price/price-modal.ts index 3911c53..f5d38ad 100644 --- a/src/app/price/price-modal.ts +++ b/src/app/price/price-modal.ts @@ -13,6 +13,8 @@ import { import { Util } from '../shared/util'; import { PriceService } from '../core/price.service'; import { Price } from '../shared/price'; +import { SessionService } from '../core/session.service'; +import { Org } from '../shared/org'; import { Observable } from 'rxjs/Observable'; @Component({ @@ -23,15 +25,18 @@ import { Observable } from 'rxjs/Observable'; export class PriceModal { public form: FormGroup; public error: AppError; + public org: Org; private originalDate: Date; constructor( public activeModal: NgbActiveModal, private log: Logger, private priceService: PriceService, + private sessionService: SessionService, private fb: FormBuilder ) { - let dateString = Util.getLocalDateString(new Date()); + this.org = this.sessionService.getOrg(); + let dateString = Util.getLocalDateString(new Date(), this.org.timezone); this.form = fb.group({ 'id': [null], @@ -47,7 +52,7 @@ export class PriceModal { this.form.patchValue({ id: data.id, currency: data.currency, - date: Util.getLocalDateString(data.date), + date: Util.getLocalDateString(data.date, this.org.timezone), price: data.price }); } @@ -56,18 +61,11 @@ export class PriceModal { this.error = null; let date = this.form.value.id ? this.originalDate : new Date(); - let formDate = Util.getDateFromLocalDateString(this.form.value.date); + let formDate = Util.getDateFromLocalDateString(this.form.value.date, this.org.timezone); - if(formDate.getTime()) { + if(formDate.getTime() && !Util.isSameDay(date, formDate, this.org.timezone)) { // make the time be at the very end of the day - formDate.setHours(23, 59, 59, 999); - } - - let sameDay = formDate.getFullYear() === date.getFullYear() && - formDate.getMonth() === date.getMonth() && - formDate.getDate() === date.getDate(); - - if(formDate.getTime() && !sameDay) { + Util.setEndOfDay(formDate, this.org.timezone); date = formDate; } diff --git a/src/app/price/pricedb.html b/src/app/price/pricedb.html index 4dbda5d..620d461 100644 --- a/src/app/price/pricedb.html +++ b/src/app/price/pricedb.html @@ -17,7 +17,7 @@
- {{price.date | date:"M/d/y"}} + {{price.date | datetz:"M/D/YYYY":org.timezone}}
{{price.price * multiplier | currencyFormat:org.precision:org.currency}} diff --git a/src/app/reconcile/reconcile-modal.html b/src/app/reconcile/reconcile-modal.html index 1284eba..7b91ae1 100644 --- a/src/app/reconcile/reconcile-modal.html +++ b/src/app/reconcile/reconcile-modal.html @@ -14,7 +14,7 @@
-
{{item.tx.date | date:"M/d/y"}}
+
{{item.tx.date | datetz:"M/D/YYYY":org.timezone}}
{{item.tx.description}}
{{item.amount | currencyFormat:account.precision:account.currency}}
@@ -26,7 +26,7 @@
-
{{item.tx.date | date:"M/d/y"}}
+
{{item.tx.date | datetz:"M/D/YYYY":org.timezone}}
{{item.tx.description}}
{{item.amount | currencyFormat:account.precision:account.currency}}
diff --git a/src/app/reconcile/reconcile-modal.ts b/src/app/reconcile/reconcile-modal.ts index 1b21dcd..6e55a6f 100644 --- a/src/app/reconcile/reconcile-modal.ts +++ b/src/app/reconcile/reconcile-modal.ts @@ -45,6 +45,7 @@ export class ReconcileModal { public balance: number; public reconciled: number; public error: AppError; + public org: Org; constructor( public activeModal: NgbActiveModal, @@ -52,7 +53,9 @@ export class ReconcileModal { private txService: TransactionService, private sessionService: SessionService, private fb: FormBuilder - ) {} + ) { + this.org = this.sessionService.getOrg(); + } setData(account: Account, rec: Reconciliation) { this.account = account; diff --git a/src/app/reconcile/reconcile.html b/src/app/reconcile/reconcile.html index 72f47eb..bd98d85 100644 --- a/src/app/reconcile/reconcile.html +++ b/src/app/reconcile/reconcile.html @@ -53,7 +53,7 @@

Past Reconciliations

- Period: {{rec.startDate | date:"M/d/y"}} - {{rec.endDate | date:"M/d/y"}}
+ Period: {{rec.startDate | datetz:"M/D/YYYY":org.timezone}} - {{rec.endDate | datetz:"M/D/YYYY":org.timezone}}
Beginning Balance: {{rec.startBalance | currencyFormat:account.precision:account.currency}}
Ending Balance: {{rec.endBalance | currencyFormat:account.precision:account.currency}}
Delete diff --git a/src/app/reconcile/reconcile.ts b/src/app/reconcile/reconcile.ts index 81e531b..e7f0f6f 100644 --- a/src/app/reconcile/reconcile.ts +++ b/src/app/reconcile/reconcile.ts @@ -14,6 +14,7 @@ import { OrgService } from '../core/org.service'; import { TransactionService } from '../core/transaction.service'; import { Account, AccountApi, AccountTree } from '../shared/account'; import { Transaction } from '../shared/transaction'; +import { Org } from '../shared/org'; import { AppError } from '../shared/error'; import { Util } from '../shared/util'; import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; @@ -37,6 +38,7 @@ export class ReconcilePage { public pastReconciliations: Reconciliation[]; public unreconciledTxs: Transaction[]; public error: AppError; + public org: Org; private accountTree: AccountTree; @ViewChild('confirmDeleteModal') confirmDeleteModal: ElementRef; @@ -50,7 +52,7 @@ export class ReconcilePage { private modalService: NgbModal, private sessionService: SessionService) { - let org = this.orgService.getCurrentOrg(); + this.org = this.orgService.getCurrentOrg(); this.accountForm = fb.group({ 'accountId': [null, Validators.required] }); @@ -85,8 +87,8 @@ export class ReconcilePage { let value = this.newReconcile.getRawValue(); let rec = new Reconciliation(); - rec.startDate = Util.getDateFromLocalDateString(value.startDate); - rec.endDate = Util.getDateFromLocalDateString(value.endDate); + rec.startDate = Util.getDateFromLocalDateString(value.startDate, this.org.timezone); + rec.endDate = Util.getDateFromLocalDateString(value.endDate, this.org.timezone); rec.startBalance = Math.round(parseFloat(value.startBalance) * Math.pow(10, this.account.precision)); rec.endBalance = Math.round(parseFloat(value.endBalance) * Math.pow(10, this.account.precision)); @@ -104,7 +106,7 @@ export class ReconcilePage { this.newReconcile.patchValue( { - startDate: Util.getLocalDateString(rec.endDate), + startDate: Util.getLocalDateString(rec.endDate, this.org.timezone), startBalance: rec.endBalance / Math.pow(10, this.account.precision), endBalance: 0, endDate: '' @@ -201,7 +203,7 @@ export class ReconcilePage { if(!dates.length) { if(firstStartDate) { - this.newReconcile.patchValue({startDate: Util.getLocalDateString(firstStartDate)}); + this.newReconcile.patchValue({startDate: Util.getLocalDateString(firstStartDate, this.org.timezone)}); } return; } @@ -226,7 +228,7 @@ export class ReconcilePage { this.newReconcile.patchValue( { - startDate: Util.getLocalDateString(lastRec.endDate), + startDate: Util.getLocalDateString(lastRec.endDate, this.org.timezone), startBalance: lastRec.endBalance / Math.pow(10, this.account.precision) } ); @@ -270,7 +272,7 @@ export class ReconcilePage { if(lastRec) { this.newReconcile.patchValue( { - startDate: Util.getLocalDateString(lastRec.endDate), + startDate: Util.getLocalDateString(lastRec.endDate, this.org.timezone), startBalance: lastRec.endBalance / Math.pow(10, this.account.precision) } ); diff --git a/src/app/reports/balancesheet.html b/src/app/reports/balancesheet.html index 9355de6..9d052b6 100644 --- a/src/app/reports/balancesheet.html +++ b/src/app/reports/balancesheet.html @@ -1,4 +1,4 @@ -

Balance Sheet
{{date | date:"shortDate"}} (options)

+

Balance Sheet
{{date.getTime() - 1 | datetz:"M/D/YYYY":org.timezone}} (options)

diff --git a/src/app/reports/balancesheet.ts b/src/app/reports/balancesheet.ts index c03713c..10b4885 100644 --- a/src/app/reports/balancesheet.ts +++ b/src/app/reports/balancesheet.ts @@ -62,15 +62,16 @@ export class BalanceSheetReport { } } + this.org = this.orgService.getCurrentOrg(); + this.form = fb.group({ - date: [Util.getLocalDateStringExcl(this.date), Validators.required], + date: [Util.getLocalDateStringExcl(this.date, this.org.timezone), Validators.required], priceSource: [this.priceSource, Validators.required] }); } ngOnInit() { this.sessionService.setLoading(true); - this.org = this.orgService.getCurrentOrg(); this.amounts = {}; this.assetAccount = null; @@ -133,7 +134,7 @@ export class BalanceSheetReport { this.treeSubscription.unsubscribe(); //this.dataService.setLoading(true); this.showOptionsForm = false; - this.date = Util.getDateFromLocalDateStringExcl(this.form.value.date); + this.date = Util.getDateFromLocalDateStringExcl(this.form.value.date, this.org.timezone); this.priceSource = this.form.value.priceSource; let reportData = this.configService.get('reportData'); diff --git a/src/app/reports/income.html b/src/app/reports/income.html index df557d4..198c887 100644 --- a/src/app/reports/income.html +++ b/src/app/reports/income.html @@ -1,4 +1,4 @@ -

Income Statement
{{startDate | date:"shortDate"}} - {{endDate.getTime() - 1 | date:"shortDate"}} (edit)

+

Income Statement
{{startDate | datetz:"M/D/YYYY":org.timezone}} - {{endDate.getTime() - 1 | datetz:"M/D/YYYY":org.timezone}} (edit)

diff --git a/src/app/reports/income.ts b/src/app/reports/income.ts index 2739a56..6e3d883 100644 --- a/src/app/reports/income.ts +++ b/src/app/reports/income.ts @@ -44,10 +44,16 @@ export class IncomeReport { private orgService: OrgService, private configService: ConfigService, private sessionService: SessionService) { + } + + ngOnInit() { + this.sessionService.setLoading(true); + this.org = this.orgService.getCurrentOrg(); + this.startDate = new Date(); - Util.setFirstOfMonth(this.startDate); - Util.setBeginOfDay(this.startDate); - this.endDate = Util.getOneMonthLater(this.startDate); + Util.setFirstOfMonth(this.startDate, this.org.timezone); + Util.setBeginOfDay(this.startDate, this.org.timezone); + this.endDate = Util.getOneMonthLater(this.startDate, this.org.timezone); let reportData = this.configService.get('reportData'); @@ -62,15 +68,10 @@ export class IncomeReport { } } - this.form = fb.group({ - startDate: [Util.getLocalDateString(this.startDate), Validators.required], - endDate: [Util.getLocalDateStringExcl(this.endDate), Validators.required] + this.form = this.fb.group({ + startDate: [Util.getLocalDateString(this.startDate, this.org.timezone), Validators.required], + endDate: [Util.getLocalDateStringExcl(this.endDate, this.org.timezone), Validators.required] }); - } - - ngOnInit() { - this.sessionService.setLoading(true); - this.org = this.orgService.getCurrentOrg(); this.treeSubscription = this.accountService.getAccountTreeWithPeriodBalance(this.startDate, this.endDate) .subscribe(tree => { @@ -90,8 +91,8 @@ export class IncomeReport { this.treeSubscription.unsubscribe(); //this.dataService.setLoading(true); this.showDateForm = false; - this.startDate = Util.getDateFromLocalDateString(this.form.value.startDate); - this.endDate = Util.getDateFromLocalDateStringExcl(this.form.value.endDate); + this.startDate = Util.getDateFromLocalDateString(this.form.value.startDate, this.org.timezone); + this.endDate = Util.getDateFromLocalDateStringExcl(this.form.value.endDate, this.org.timezone); let reportData = this.configService.get('reportData'); diff --git a/src/app/shared/datetz.pipe.ts b/src/app/shared/datetz.pipe.ts new file mode 100644 index 0000000..df18164 --- /dev/null +++ b/src/app/shared/datetz.pipe.ts @@ -0,0 +1,14 @@ +import { Pipe, PipeTransform } from '@angular/core'; +//import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'; +import * as moment from 'moment-timezone'; + +@Pipe({name: 'datetz'}) +export class DateTzPipe implements PipeTransform { + constructor() { + } + + transform(date: Date, format: string, tz: string): string { + let m = moment(date).tz(tz || moment.tz.guess()); + return m.format(format); + } +} \ No newline at end of file diff --git a/src/app/shared/org.ts b/src/app/shared/org.ts index 365b0d5..e5026d9 100644 --- a/src/app/shared/org.ts +++ b/src/app/shared/org.ts @@ -5,6 +5,7 @@ export class Org { name: string; currency: string; precision: number; + timezone: string; constructor(options: any = {}) { this.id = options.id; this.inserted = options.inserted ? new Date(options.inserted) : null; @@ -12,5 +13,6 @@ export class Org { this.name = options.name; this.currency = options.currency; this.precision = options.precision && parseInt(options.precision); + this.timezone = options.timezone; } } \ No newline at end of file diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index d7634d3..443284f 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -3,11 +3,12 @@ import { DecimalPipe } from '@angular/common'; import { CurrencyFormatPipe } from './currency-format.pipe'; import { AccountNamePipe } from './account-name.pipe'; import { AccountBalancePipe } from './account-balance.pipe'; +import { DateTzPipe } from './datetz.pipe'; @NgModule({ imports: [], - declarations: [CurrencyFormatPipe, AccountNamePipe, AccountBalancePipe], - exports: [CurrencyFormatPipe, AccountNamePipe, AccountBalancePipe], + declarations: [CurrencyFormatPipe, AccountNamePipe, AccountBalancePipe, DateTzPipe], + exports: [CurrencyFormatPipe, AccountNamePipe, AccountBalancePipe, DateTzPipe], providers: [DecimalPipe, CurrencyFormatPipe] }) export class SharedModule { } \ No newline at end of file diff --git a/src/app/shared/util.ts b/src/app/shared/util.ts index 1dba80f..a190f1a 100644 --- a/src/app/shared/util.ts +++ b/src/app/shared/util.ts @@ -4,8 +4,8 @@ import * as moment from 'moment-timezone'; const defaultTz = moment.tz.guess(); export class Util { - static getLocalDateString(input: Date, tz: string = defaultTz) { - let m = moment(input).tz(tz); + static getLocalDateString(input: Date, tz: string) { + let m = moment(input).tz(tz || defaultTz); let year = m.format('YYYY'); let month = m.format('MM'); @@ -22,8 +22,8 @@ export class Util { return year + '-' + month + '-' + date; } - static getLocalDateStringExcl(input: Date, tz: string = defaultTz) { - let m = moment(input.getTime() - 1).tz(tz); + static getLocalDateStringExcl(input: Date, tz: string) { + let m = moment(input.getTime() - 1).tz(tz || defaultTz); let year = m.format('YYYY'); let month = m.format('MM'); @@ -40,10 +40,10 @@ export class Util { return year + '-' + month + '-' + date; } - static getDateFromLocalDateString(input: string, tz: string = defaultTz) { + static getDateFromLocalDateString(input: string, tz: string) { let parts = input.split('-'); - let m = moment().tz(tz); + let m = moment().tz(tz || defaultTz); m.hours(0); m.minutes(0); m.seconds(0); @@ -55,10 +55,10 @@ export class Util { return m.toDate(); } - static getDateFromLocalDateStringExcl(input: string, tz: string = defaultTz) { + static getDateFromLocalDateStringExcl(input: string, tz: string) { let parts = input.split('-'); - let m = moment().tz(tz); + let m = moment().tz(tz || defaultTz); m.hours(0); m.minutes(0); m.seconds(0); @@ -70,15 +70,15 @@ export class Util { return m.toDate(); } - static setFirstOfMonth(input: Date, tz: string = defaultTz) { - let m = moment(input).tz(tz); + static setFirstOfMonth(input: Date, tz: string) { + let m = moment(input).tz(tz || defaultTz); m.date(1); input.setTime(m.valueOf()); } - static setBeginOfDay(input: Date, tz: string = defaultTz) { - let m = moment(input).tz(tz); + static setBeginOfDay(input: Date, tz: string) { + let m = moment(input).tz(tz || defaultTz); m.hours(0); m.minutes(0); @@ -87,8 +87,8 @@ export class Util { input.setTime(m.valueOf()); } - static setEndOfDay(input: Date, tz: string = defaultTz) { - let m = moment(input).tz(tz); + static setEndOfDay(input: Date, tz: string) { + let m = moment(input).tz(tz || defaultTz); m.hours(23); m.minutes(59); @@ -97,21 +97,21 @@ export class Util { input.setTime(m.valueOf()); } - static getOneMonthLater(input: Date, tz: string = defaultTz): Date { - let m = moment(input).tz(tz); + static getOneMonthLater(input: Date, tz: string): Date { + let m = moment(input).tz(tz || defaultTz); m.month(m.month() + 1); return m.toDate(); } - static computeTransactionDate(formDate: Date, txDate: Date, tz: string = defaultTz): Date { + static computeTransactionDate(formDate: Date, txDate: Date, tz: string): Date { if(!formDate || !formDate.getTime()) { return txDate; } - let formMoment = moment(formDate).tz(tz); - let txMoment = moment(txDate).tz(tz); + let formMoment = moment(formDate).tz(tz || defaultTz); + let txMoment = moment(txDate).tz(tz || defaultTz); // make the time be at the very end of the day formMoment.hours(23); @@ -123,11 +123,45 @@ export class Util { formMoment.month() === txMoment.month() && formMoment.date() === txMoment.date(); - if(!sameDay) { - return formMoment.toDate(); + if(sameDay) { + return txDate; } - return txDate; + if(formDate < txDate) { + // make time end of day for past dates + formMoment.hours(23); + formMoment.minutes(59); + formMoment.seconds(59); + formMoment.milliseconds(999); + } else { + // make time beginning of day for future dates + formMoment.hours(0); + formMoment.minutes(0); + formMoment.seconds(0); + formMoment.milliseconds(0); + } + + return formMoment.toDate(); + } + + static isSameDay(date1: Date, date2: Date, tz: string) { + let m1 = moment(date1).tz(tz || defaultTz); + let m2 = moment(date2).tz(tz || defaultTz); + + return m1.year() === m2.year() && + m1.month() === m2.month() && + m1.date() === m2.date(); + } + + static getPeriodStart(tz: string): Date { + let m = moment().tz(tz || defaultTz); + m.date(1); + m.hours(0); + m.minutes(0); + m.seconds(0); + m.milliseconds(0); + + return m.toDate(); } static newGuid() { diff --git a/src/app/transaction/advancededit.ts b/src/app/transaction/advancededit.ts index b09d891..1d3bf04 100644 --- a/src/app/transaction/advancededit.ts +++ b/src/app/transaction/advancededit.ts @@ -50,7 +50,7 @@ export class AdvancedEdit { this.org = this.orgService.getCurrentOrg(); - let dateString = Util.getLocalDateString(item.tx.date); + let dateString = Util.getLocalDateString(item.tx.date, this.org.timezone); this.form = new FormGroup({ date: new FormControl(dateString), @@ -110,20 +110,9 @@ export class AdvancedEdit { this.error = null; let date = this.item.tx.id ? this.item.tx.date : new Date(); - let formDate = Util.getDateFromLocalDateString(this.form.value.date); + let formDate = Util.getDateFromLocalDateString(this.form.value.date, this.org.timezone); - if(formDate.getTime()) { - // make the time be at the very end of the day - formDate.setHours(23, 59, 59, 999); - } - - let sameDay = formDate.getFullYear() === date.getFullYear() && - formDate.getMonth() === date.getMonth() && - formDate.getDate() === date.getDate(); - - if(formDate.getTime() && !sameDay) { - date = formDate; - } + date = Util.computeTransactionDate(formDate, date, this.org.timezone); let tx = new Transaction({ id: this.item.tx.id, diff --git a/src/app/transaction/list.html b/src/app/transaction/list.html index a9c553e..f3fccd8 100644 --- a/src/app/transaction/list.html +++ b/src/app/transaction/list.html @@ -35,7 +35,7 @@
- {{item.tx.date | date:"M/d/y"}} + {{item.tx.date | datetz:"M/D/YYYY":org.timezone}}
diff --git a/src/app/transaction/list.ts b/src/app/transaction/list.ts index d0fa5d7..21b160a 100644 --- a/src/app/transaction/list.ts +++ b/src/app/transaction/list.ts @@ -2,6 +2,7 @@ import { Component, Input, OnInit, ViewChild, ElementRef, AfterViewChecked, Rend import { Logger } from '../core/logger'; import { ActivatedRoute } from '@angular/router'; import { TransactionService } from '../core/transaction.service'; +import { OrgService } from '../core/org.service'; import { AccountService } from '../core/account.service'; import { Account, AccountTree } from '../shared/account'; import { Transaction, Split} from '../shared/transaction'; @@ -22,6 +23,7 @@ import 'rxjs/add/operator/mergeMap'; import { AdvancedEdit } from './advancededit'; import { TxItem } from './txitem'; import { Subject } from 'rxjs'; +import { Org } from '../shared/org'; @Component({ selector: 'app-txlist', @@ -34,6 +36,7 @@ export class TxListPage implements OnInit, AfterViewChecked { public account: Account; public items: TxItem[]; public error: AppError; + public org: Org; private accountId: string; private accountTree: AccountTree; private balance: number; @@ -54,6 +57,7 @@ export class TxListPage implements OnInit, AfterViewChecked { private log: Logger, private route: ActivatedRoute, private txService: TransactionService, + private orgService: OrgService, private accountService: AccountService, private fb: FormBuilder, private renderer: Renderer, @@ -70,6 +74,9 @@ export class TxListPage implements OnInit, AfterViewChecked { ngOnInit() { this.accountId = this.route.snapshot.paramMap.get('id'); //+this.route.snapshot.paramMap.get('id'); + this.org = this.orgService.getCurrentOrg(); + + console.log(this.org); this.accountService.getAccountTree().subscribe(tree => { this.account = tree.accountMap[this.accountId]; @@ -88,7 +95,7 @@ export class TxListPage implements OnInit, AfterViewChecked { splits: [] }); - newTx.date.setHours(23, 59, 59, 999); + Util.setEndOfDay(newTx.date, this.org.timezone); newTx.splits.push(new Split({ accountId: this.account.id @@ -403,7 +410,7 @@ export class TxListPage implements OnInit, AfterViewChecked { item.editing = true; - let dateString = Util.getLocalDateString(item.tx.date); + let dateString = Util.getLocalDateString(item.tx.date, this.org.timezone); this.log.debug(item); let debit = this.getDebit(item); @@ -622,9 +629,9 @@ export class TxListPage implements OnInit, AfterViewChecked { } let date = item.tx.id ? item.tx.date : new Date(); - let formDate = Util.getDateFromLocalDateString(item.form.value.date); + let formDate = Util.getDateFromLocalDateString(item.form.value.date, this.org.timezone); - date = Util.computeTransactionDate(formDate, date); + date = Util.computeTransactionDate(formDate, date, this.org.timezone); let tx = new Transaction({ id: item.tx.id, @@ -707,7 +714,7 @@ export class TxListPage implements OnInit, AfterViewChecked { splits: [] }); - newTx.date.setHours(23, 59, 59, 999); + Util.setEndOfDay(newTx.date, this.org.timezone); newTx.splits.push(new Split({ accountId: this.account.id @@ -825,11 +832,11 @@ export class TxListPage implements OnInit, AfterViewChecked { autocomplete(item: TxItem, tx: Transaction) { this.log.debug('chose tx', tx); - let formDate = Util.getDateFromLocalDateString(item.form.value.date); + let formDate = Util.getDateFromLocalDateString(item.form.value.date, this.org.timezone); item.tx = new Transaction( { id: item.tx.id, - date: Util.computeTransactionDate(formDate, new Date()), + date: Util.computeTransactionDate(formDate, new Date(), this.org.timezone), description: tx.description, splits: tx.splits } diff --git a/src/app/transaction/new.ts b/src/app/transaction/new.ts index 9e81642..4defc4e 100644 --- a/src/app/transaction/new.ts +++ b/src/app/transaction/new.ts @@ -17,6 +17,7 @@ import { Util } from '../shared/util'; import { AppError } from '../shared/error'; import { Transaction, Split } from '../shared/transaction'; import { Logger } from '../core/logger'; +import { Org } from '../shared/org'; @Component({ selector: 'app-txnew', @@ -45,6 +46,7 @@ export class NewTransactionPage { public openingBalances: Account; public accountTree: AccountTree; public accountMap: any; + public org; @ViewChild('acc') acc: any; @ViewChild('amount') amount: ElementRef @@ -57,12 +59,10 @@ export class NewTransactionPage { private orgService: OrgService, private fb: FormBuilder, private log: Logger) { - this.numAccountsShown = 3; + this.org = this.orgService.getCurrentOrg(); - let org = this.orgService.getCurrentOrg(); - - let dateString = Util.getLocalDateString(new Date()); + let dateString = Util.getLocalDateString(new Date(), this.org.timezone); this.form = this.fb.group({ type: ['', Validators.required], firstAccountPrimary: [null, Validators.required], @@ -226,20 +226,9 @@ export class NewTransactionPage { this.error = null; let date = new Date(); - let formDate = Util.getDateFromLocalDateString(this.form.value.date); + let formDate = Util.getDateFromLocalDateString(this.form.value.date, this.org.timezone); - if (formDate.getTime()) { - // make the time be at the very end of the day - formDate.setHours(23, 59, 59, 999); - } - - let sameDay = formDate.getFullYear() === date.getFullYear() && - formDate.getMonth() === date.getMonth() && - formDate.getDate() === date.getDate(); - - if (formDate.getTime() && !sameDay) { - date = formDate; - } + date = Util.computeTransactionDate(formDate, date, this.org.timezone); let tx = new Transaction({ id: Util.newGuid(), From 5b720b79c4d08d90e52780b5df27ad8fb637aa99 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 27 Jun 2019 16:26:31 -0400 Subject: [PATCH 3/8] update org timezone --- src/app/core/api.service.ts | 5 +++++ src/app/core/org.service.ts | 8 +++++++ src/app/org/org.html | 45 +++++++++++++++++++++++++++++++++++++ src/app/org/org.ts | 42 ++++++++++++++++++++++++++++++++++ src/app/shared/util.ts | 9 ++++++++ 5 files changed, 109 insertions(+) diff --git a/src/app/core/api.service.ts b/src/app/core/api.service.ts index e61996f..fd0650f 100644 --- a/src/app/core/api.service.ts +++ b/src/app/core/api.service.ts @@ -231,6 +231,11 @@ export class ApiService { .pipe(catchError(this.handleError)); } + putOrg(org: Org): Observable { + return this.http.put(this.url + '/orgs/' + this.orgId, org, this.httpOptions) + .pipe(catchError(this.handleError)); + } + getPricesNearestInTime(date: Date): Observable { let query = '/orgs/' + this.orgId + '/prices?nearestDate=' + date.getTime(); return this.http.get(this.url + query, this.httpOptions) diff --git a/src/app/core/org.service.ts b/src/app/core/org.service.ts index 007ec77..b54478d 100644 --- a/src/app/core/org.service.ts +++ b/src/app/core/org.service.ts @@ -59,6 +59,14 @@ export class OrgService { }); } + updateOrg(org: Org): Observable { + return this.apiService.putOrg(org) + .do(org => { + this.org = org; + this.sessionService.switchOrg(this.org); + }) + } + getInvites(): Observable { return this.apiService.getInvites(); } diff --git a/src/app/org/org.html b/src/app/org/org.html index a376751..cd60567 100644 --- a/src/app/org/org.html +++ b/src/app/org/org.html @@ -1,6 +1,41 @@

Organization

+

Current Organization

+ + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+

{{updateOrgError.message}}

+ + +

Choose Organization

@@ -103,6 +138,16 @@
+
+ +
+ +
+
diff --git a/src/app/org/org.ts b/src/app/org/org.ts index e5e570c..4c67aea 100644 --- a/src/app/org/org.ts +++ b/src/app/org/org.ts @@ -30,7 +30,11 @@ export class OrgPage { public inviteFormError: AppError; public newOrgForm: FormGroup; public newOrgError: AppError; + public updateOrgForm: FormGroup; + public updateOrgError: AppError; public invites: Invite[]; + public timezones: string[]; + public defaultTz: string; constructor( private log: Logger, @@ -38,8 +42,19 @@ export class OrgPage { private fb: FormBuilder ) { + this.timezones = Util.getTimezones(); + this.defaultTz = Util.getDefaultTimezone(); + + console.log('defaultTz', this.defaultTz); this.invites = null; + this.updateOrgForm = fb.group({ + 'name': ['', Validators.required], + 'currency': [{value: '', disabled: true}, Validators.required], + 'precision': [{value: null, disabled: true}, Validators.required], + 'timezone': ['', Validators.required] + }); + this.chooseOrgForm = fb.group({ 'id': [null, Validators.required] }); @@ -56,6 +71,7 @@ export class OrgPage { 'name': ['', Validators.required], 'currency': ['', Validators.required], 'precision': [null, Validators.required], + 'timezone': [this.defaultTz, Validators.required], 'createDefaultAccounts': [true, Validators.required] }); } @@ -63,12 +79,22 @@ export class OrgPage { ngOnInit() { this.currentOrg = this.orgService.getCurrentOrg(); + this.updateOrgForm.setValue( + { + name: this.currentOrg.name, + currency: this.currentOrg.currency, + precision: this.currentOrg.precision, + timezone: this.currentOrg.timezone + } + ); + this.chooseOrgForm.setValue({id: this.currentOrg.id}); this.newOrgForm.setValue( { name: '', currency: this.currentOrg.currency, precision: this.currentOrg.precision, + timezone: this.defaultTz, createDefaultAccounts: true } ); @@ -139,6 +165,22 @@ export class OrgPage { ); } + updateOrgSubmit() { + let org = this.currentOrg; + org.name = this.updateOrgForm.get('name').value; + org.timezone = this.updateOrgForm.get('timezone').value; + + this.orgService.updateOrg(org) + .subscribe( + org => { + this.log.debug(org); + }, + error => { + this.updateOrgError = error; + } + ); + } + deleteInvite(invite: Invite) { this.orgService.deleteInvite(invite.id).subscribe(() => { this.invites = this.invites.filter(inv => { diff --git a/src/app/shared/util.ts b/src/app/shared/util.ts index a190f1a..e670eae 100644 --- a/src/app/shared/util.ts +++ b/src/app/shared/util.ts @@ -164,6 +164,15 @@ export class Util { return m.toDate(); } + static getTimezones(): string[] { + let timezones = ['']; + return timezones.concat(moment.tz.names()); + } + + static getDefaultTimezone(): string { + return defaultTz; + } + static newGuid() { let arr = new Uint8Array(16); window.crypto.getRandomValues(arr); From 714a1b187ba8759f1f8bf1eaa1361ce1087efbbd Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 27 Jun 2019 16:37:46 -0400 Subject: [PATCH 4/8] separate out date functions --- src/app/dashboard/dashboard.ts | 4 +- src/app/org/org.ts | 5 +- src/app/price/price-modal.ts | 11 +- src/app/price/pricedb.ts | 1 - src/app/reconcile/reconcile.ts | 13 ++- src/app/reports/balancesheet.ts | 6 +- src/app/reports/income.ts | 16 +-- src/app/shared/dateutil.ts | 175 ++++++++++++++++++++++++++++ src/app/shared/util.ts | 174 --------------------------- src/app/transaction/advancededit.ts | 7 +- src/app/transaction/list.ts | 17 ++- src/app/transaction/new.ts | 7 +- 12 files changed, 220 insertions(+), 216 deletions(-) create mode 100644 src/app/shared/dateutil.ts diff --git a/src/app/dashboard/dashboard.ts b/src/app/dashboard/dashboard.ts index 0e89728..86905b8 100644 --- a/src/app/dashboard/dashboard.ts +++ b/src/app/dashboard/dashboard.ts @@ -7,7 +7,7 @@ import { SessionService } from '../core/session.service'; import { Transaction, Split } from '../shared/transaction'; import { Org } from '../shared/org'; import { Account, AccountTree } from '../shared/account'; -import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; import { TxListPage } from '../transaction/list'; import { IncomeReport } from '../reports/income'; import { Observable } from 'rxjs/Observable'; @@ -51,7 +51,7 @@ export class DashboardPage implements OnInit { this.org = this.orgService.getCurrentOrg(); this.log.debug('org', this.org); - let periodStart = Util.getPeriodStart(this.org.timezone); + let periodStart = DateUtil.getPeriodStart(this.org.timezone); let tree$ = this.accountService.getAccountTreeWithPeriodBalance(periodStart); diff --git a/src/app/org/org.ts b/src/app/org/org.ts index 4c67aea..2488e6c 100644 --- a/src/app/org/org.ts +++ b/src/app/org/org.ts @@ -14,6 +14,7 @@ import { Org } from '../shared/org'; import { Invite } from '../shared/invite'; import { AppError } from '../shared/error'; import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; @Component({ selector: 'app-org', @@ -42,8 +43,8 @@ export class OrgPage { private fb: FormBuilder ) { - this.timezones = Util.getTimezones(); - this.defaultTz = Util.getDefaultTimezone(); + this.timezones = DateUtil.getTimezones(); + this.defaultTz = DateUtil.getDefaultTimezone(); console.log('defaultTz', this.defaultTz); this.invites = null; diff --git a/src/app/price/price-modal.ts b/src/app/price/price-modal.ts index f5d38ad..6b768bc 100644 --- a/src/app/price/price-modal.ts +++ b/src/app/price/price-modal.ts @@ -11,6 +11,7 @@ import { AbstractControl } from '@angular/forms'; import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; import { PriceService } from '../core/price.service'; import { Price } from '../shared/price'; import { SessionService } from '../core/session.service'; @@ -36,7 +37,7 @@ export class PriceModal { private fb: FormBuilder ) { this.org = this.sessionService.getOrg(); - let dateString = Util.getLocalDateString(new Date(), this.org.timezone); + let dateString = DateUtil.getLocalDateString(new Date(), this.org.timezone); this.form = fb.group({ 'id': [null], @@ -52,7 +53,7 @@ export class PriceModal { this.form.patchValue({ id: data.id, currency: data.currency, - date: Util.getLocalDateString(data.date, this.org.timezone), + date: DateUtil.getLocalDateString(data.date, this.org.timezone), price: data.price }); } @@ -61,11 +62,11 @@ export class PriceModal { this.error = null; let date = this.form.value.id ? this.originalDate : new Date(); - let formDate = Util.getDateFromLocalDateString(this.form.value.date, this.org.timezone); + let formDate = DateUtil.getDateFromLocalDateString(this.form.value.date, this.org.timezone); - if(formDate.getTime() && !Util.isSameDay(date, formDate, this.org.timezone)) { + if(formDate.getTime() && !DateUtil.isSameDay(date, formDate, this.org.timezone)) { // make the time be at the very end of the day - Util.setEndOfDay(formDate, this.org.timezone); + DateUtil.setEndOfDay(formDate, this.org.timezone); date = formDate; } diff --git a/src/app/price/pricedb.ts b/src/app/price/pricedb.ts index c792023..8a130bb 100644 --- a/src/app/price/pricedb.ts +++ b/src/app/price/pricedb.ts @@ -13,7 +13,6 @@ import { PriceService } from '../core/price.service'; import { Price } from '../shared/price'; import { Org } from '../shared/org'; import { AppError } from '../shared/error'; -import { Util } from '../shared/util'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/forkJoin'; import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; diff --git a/src/app/reconcile/reconcile.ts b/src/app/reconcile/reconcile.ts index e7f0f6f..d44ad3c 100644 --- a/src/app/reconcile/reconcile.ts +++ b/src/app/reconcile/reconcile.ts @@ -17,6 +17,7 @@ import { Transaction } from '../shared/transaction'; import { Org } from '../shared/org'; import { AppError } from '../shared/error'; import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; import { ReconcileModal } from './reconcile-modal'; import { Reconciliation } from './reconciliation'; @@ -87,8 +88,8 @@ export class ReconcilePage { let value = this.newReconcile.getRawValue(); let rec = new Reconciliation(); - rec.startDate = Util.getDateFromLocalDateString(value.startDate, this.org.timezone); - rec.endDate = Util.getDateFromLocalDateString(value.endDate, this.org.timezone); + rec.startDate = DateUtil.getDateFromLocalDateString(value.startDate, this.org.timezone); + rec.endDate = DateUtil.getDateFromLocalDateString(value.endDate, this.org.timezone); rec.startBalance = Math.round(parseFloat(value.startBalance) * Math.pow(10, this.account.precision)); rec.endBalance = Math.round(parseFloat(value.endBalance) * Math.pow(10, this.account.precision)); @@ -106,7 +107,7 @@ export class ReconcilePage { this.newReconcile.patchValue( { - startDate: Util.getLocalDateString(rec.endDate, this.org.timezone), + startDate: DateUtil.getLocalDateString(rec.endDate, this.org.timezone), startBalance: rec.endBalance / Math.pow(10, this.account.precision), endBalance: 0, endDate: '' @@ -203,7 +204,7 @@ export class ReconcilePage { if(!dates.length) { if(firstStartDate) { - this.newReconcile.patchValue({startDate: Util.getLocalDateString(firstStartDate, this.org.timezone)}); + this.newReconcile.patchValue({startDate: DateUtil.getLocalDateString(firstStartDate, this.org.timezone)}); } return; } @@ -228,7 +229,7 @@ export class ReconcilePage { this.newReconcile.patchValue( { - startDate: Util.getLocalDateString(lastRec.endDate, this.org.timezone), + startDate: DateUtil.getLocalDateString(lastRec.endDate, this.org.timezone), startBalance: lastRec.endBalance / Math.pow(10, this.account.precision) } ); @@ -272,7 +273,7 @@ export class ReconcilePage { if(lastRec) { this.newReconcile.patchValue( { - startDate: Util.getLocalDateString(lastRec.endDate, this.org.timezone), + startDate: DateUtil.getLocalDateString(lastRec.endDate, this.org.timezone), startBalance: lastRec.endBalance / Math.pow(10, this.account.precision) } ); diff --git a/src/app/reports/balancesheet.ts b/src/app/reports/balancesheet.ts index 10b4885..281bbab 100644 --- a/src/app/reports/balancesheet.ts +++ b/src/app/reports/balancesheet.ts @@ -17,7 +17,7 @@ import { ValidationErrors } from '@angular/forms'; import { AppError } from '../shared/error'; -import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; @Component({ selector: 'app-balancesheet', @@ -65,7 +65,7 @@ export class BalanceSheetReport { this.org = this.orgService.getCurrentOrg(); this.form = fb.group({ - date: [Util.getLocalDateStringExcl(this.date, this.org.timezone), Validators.required], + date: [DateUtil.getLocalDateStringExcl(this.date, this.org.timezone), Validators.required], priceSource: [this.priceSource, Validators.required] }); } @@ -134,7 +134,7 @@ export class BalanceSheetReport { this.treeSubscription.unsubscribe(); //this.dataService.setLoading(true); this.showOptionsForm = false; - this.date = Util.getDateFromLocalDateStringExcl(this.form.value.date, this.org.timezone); + this.date = DateUtil.getDateFromLocalDateStringExcl(this.form.value.date, this.org.timezone); this.priceSource = this.form.value.priceSource; let reportData = this.configService.get('reportData'); diff --git a/src/app/reports/income.ts b/src/app/reports/income.ts index 6e3d883..c02dcdd 100644 --- a/src/app/reports/income.ts +++ b/src/app/reports/income.ts @@ -18,7 +18,7 @@ import { ValidationErrors } from '@angular/forms'; import { AppError } from '../shared/error'; -import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; @Component({ selector: 'app-income', @@ -51,9 +51,9 @@ export class IncomeReport { this.org = this.orgService.getCurrentOrg(); this.startDate = new Date(); - Util.setFirstOfMonth(this.startDate, this.org.timezone); - Util.setBeginOfDay(this.startDate, this.org.timezone); - this.endDate = Util.getOneMonthLater(this.startDate, this.org.timezone); + DateUtil.setFirstOfMonth(this.startDate, this.org.timezone); + DateUtil.setBeginOfDay(this.startDate, this.org.timezone); + this.endDate = DateUtil.getOneMonthLater(this.startDate, this.org.timezone); let reportData = this.configService.get('reportData'); @@ -69,8 +69,8 @@ export class IncomeReport { } this.form = this.fb.group({ - startDate: [Util.getLocalDateString(this.startDate, this.org.timezone), Validators.required], - endDate: [Util.getLocalDateStringExcl(this.endDate, this.org.timezone), Validators.required] + startDate: [DateUtil.getLocalDateString(this.startDate, this.org.timezone), Validators.required], + endDate: [DateUtil.getLocalDateStringExcl(this.endDate, this.org.timezone), Validators.required] }); this.treeSubscription = this.accountService.getAccountTreeWithPeriodBalance(this.startDate, this.endDate) @@ -91,8 +91,8 @@ export class IncomeReport { this.treeSubscription.unsubscribe(); //this.dataService.setLoading(true); this.showDateForm = false; - this.startDate = Util.getDateFromLocalDateString(this.form.value.startDate, this.org.timezone); - this.endDate = Util.getDateFromLocalDateStringExcl(this.form.value.endDate, this.org.timezone); + this.startDate = DateUtil.getDateFromLocalDateString(this.form.value.startDate, this.org.timezone); + this.endDate = DateUtil.getDateFromLocalDateStringExcl(this.form.value.endDate, this.org.timezone); let reportData = this.configService.get('reportData'); diff --git a/src/app/shared/dateutil.ts b/src/app/shared/dateutil.ts new file mode 100644 index 0000000..3625029 --- /dev/null +++ b/src/app/shared/dateutil.ts @@ -0,0 +1,175 @@ +//import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'; +import * as moment from 'moment-timezone'; + +const defaultTz = moment.tz.guess(); + +export class DateUtil { + static getLocalDateString(input: Date, tz: string) { + let m = moment(input).tz(tz || defaultTz); + + let year = m.format('YYYY'); + let month = m.format('MM'); + let date = m.format('DD'); + + if(month.length < 2) { + month = '0' + month; + } + + if(date.length < 2) { + date = '0' + date; + } + + return year + '-' + month + '-' + date; + } + + static getLocalDateStringExcl(input: Date, tz: string) { + let m = moment(input.getTime() - 1).tz(tz || defaultTz); + + let year = m.format('YYYY'); + let month = m.format('MM'); + let date = m.format('DD'); + + if(month.length < 2) { + month = '0' + month; + } + + if(date.length < 2) { + date = '0' + date; + } + + return year + '-' + month + '-' + date; + } + + static getDateFromLocalDateString(input: string, tz: string) { + let parts = input.split('-'); + + let m = moment().tz(tz || defaultTz); + m.hours(0); + m.minutes(0); + m.seconds(0); + m.milliseconds(0); + m.year(parseInt(parts[0])); + m.month(parseInt(parts[1]) - 1); + m.date(parseInt(parts[2])); + + return m.toDate(); + } + + static getDateFromLocalDateStringExcl(input: string, tz: string) { + let parts = input.split('-'); + + let m = moment().tz(tz || defaultTz); + m.hours(0); + m.minutes(0); + m.seconds(0); + m.milliseconds(0); + m.year(parseInt(parts[0])); + m.month(parseInt(parts[1]) - 1); + m.date(parseInt(parts[2]) + 1); + + return m.toDate(); + } + + static setFirstOfMonth(input: Date, tz: string) { + let m = moment(input).tz(tz || defaultTz); + + m.date(1); + input.setTime(m.valueOf()); + } + + static setBeginOfDay(input: Date, tz: string) { + let m = moment(input).tz(tz || defaultTz); + + m.hours(0); + m.minutes(0); + m.seconds(0); + m.milliseconds(0); + input.setTime(m.valueOf()); + } + + static setEndOfDay(input: Date, tz: string) { + let m = moment(input).tz(tz || defaultTz); + + m.hours(23); + m.minutes(59); + m.seconds(59); + m.milliseconds(999); + input.setTime(m.valueOf()); + } + + static getOneMonthLater(input: Date, tz: string): Date { + let m = moment(input).tz(tz || defaultTz); + + m.month(m.month() + 1); + + return m.toDate(); + } + + static computeTransactionDate(formDate: Date, txDate: Date, tz: string): Date { + if(!formDate || !formDate.getTime()) { + return txDate; + } + + let formMoment = moment(formDate).tz(tz || defaultTz); + let txMoment = moment(txDate).tz(tz || defaultTz); + + // make the time be at the very end of the day + formMoment.hours(23); + formMoment.minutes(59); + formMoment.seconds(59); + formMoment.milliseconds(999); + + let sameDay = formMoment.year() === txMoment.year() && + formMoment.month() === txMoment.month() && + formMoment.date() === txMoment.date(); + + if(sameDay) { + return txDate; + } + + if(formDate < txDate) { + // make time end of day for past dates + formMoment.hours(23); + formMoment.minutes(59); + formMoment.seconds(59); + formMoment.milliseconds(999); + } else { + // make time beginning of day for future dates + formMoment.hours(0); + formMoment.minutes(0); + formMoment.seconds(0); + formMoment.milliseconds(0); + } + + return formMoment.toDate(); + } + + static isSameDay(date1: Date, date2: Date, tz: string) { + let m1 = moment(date1).tz(tz || defaultTz); + let m2 = moment(date2).tz(tz || defaultTz); + + return m1.year() === m2.year() && + m1.month() === m2.month() && + m1.date() === m2.date(); + } + + static getPeriodStart(tz: string): Date { + let m = moment().tz(tz || defaultTz); + m.date(1); + m.hours(0); + m.minutes(0); + m.seconds(0); + m.milliseconds(0); + + return m.toDate(); + } + + static getTimezones(): string[] { + let timezones = ['']; + return timezones.concat(moment.tz.names()); + } + + static getDefaultTimezone(): string { + return defaultTz; + } +} \ No newline at end of file diff --git a/src/app/shared/util.ts b/src/app/shared/util.ts index e670eae..d1152c4 100644 --- a/src/app/shared/util.ts +++ b/src/app/shared/util.ts @@ -1,178 +1,4 @@ -//import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'; -import * as moment from 'moment-timezone'; - -const defaultTz = moment.tz.guess(); - export class Util { - static getLocalDateString(input: Date, tz: string) { - let m = moment(input).tz(tz || defaultTz); - - let year = m.format('YYYY'); - let month = m.format('MM'); - let date = m.format('DD'); - - if(month.length < 2) { - month = '0' + month; - } - - if(date.length < 2) { - date = '0' + date; - } - - return year + '-' + month + '-' + date; - } - - static getLocalDateStringExcl(input: Date, tz: string) { - let m = moment(input.getTime() - 1).tz(tz || defaultTz); - - let year = m.format('YYYY'); - let month = m.format('MM'); - let date = m.format('DD'); - - if(month.length < 2) { - month = '0' + month; - } - - if(date.length < 2) { - date = '0' + date; - } - - return year + '-' + month + '-' + date; - } - - static getDateFromLocalDateString(input: string, tz: string) { - let parts = input.split('-'); - - let m = moment().tz(tz || defaultTz); - m.hours(0); - m.minutes(0); - m.seconds(0); - m.milliseconds(0); - m.year(parseInt(parts[0])); - m.month(parseInt(parts[1]) - 1); - m.date(parseInt(parts[2])); - - return m.toDate(); - } - - static getDateFromLocalDateStringExcl(input: string, tz: string) { - let parts = input.split('-'); - - let m = moment().tz(tz || defaultTz); - m.hours(0); - m.minutes(0); - m.seconds(0); - m.milliseconds(0); - m.year(parseInt(parts[0])); - m.month(parseInt(parts[1]) - 1); - m.date(parseInt(parts[2]) + 1); - - return m.toDate(); - } - - static setFirstOfMonth(input: Date, tz: string) { - let m = moment(input).tz(tz || defaultTz); - - m.date(1); - input.setTime(m.valueOf()); - } - - static setBeginOfDay(input: Date, tz: string) { - let m = moment(input).tz(tz || defaultTz); - - m.hours(0); - m.minutes(0); - m.seconds(0); - m.milliseconds(0); - input.setTime(m.valueOf()); - } - - static setEndOfDay(input: Date, tz: string) { - let m = moment(input).tz(tz || defaultTz); - - m.hours(23); - m.minutes(59); - m.seconds(59); - m.milliseconds(999); - input.setTime(m.valueOf()); - } - - static getOneMonthLater(input: Date, tz: string): Date { - let m = moment(input).tz(tz || defaultTz); - - m.month(m.month() + 1); - - return m.toDate(); - } - - static computeTransactionDate(formDate: Date, txDate: Date, tz: string): Date { - if(!formDate || !formDate.getTime()) { - return txDate; - } - - let formMoment = moment(formDate).tz(tz || defaultTz); - let txMoment = moment(txDate).tz(tz || defaultTz); - - // make the time be at the very end of the day - formMoment.hours(23); - formMoment.minutes(59); - formMoment.seconds(59); - formMoment.milliseconds(999); - - let sameDay = formMoment.year() === txMoment.year() && - formMoment.month() === txMoment.month() && - formMoment.date() === txMoment.date(); - - if(sameDay) { - return txDate; - } - - if(formDate < txDate) { - // make time end of day for past dates - formMoment.hours(23); - formMoment.minutes(59); - formMoment.seconds(59); - formMoment.milliseconds(999); - } else { - // make time beginning of day for future dates - formMoment.hours(0); - formMoment.minutes(0); - formMoment.seconds(0); - formMoment.milliseconds(0); - } - - return formMoment.toDate(); - } - - static isSameDay(date1: Date, date2: Date, tz: string) { - let m1 = moment(date1).tz(tz || defaultTz); - let m2 = moment(date2).tz(tz || defaultTz); - - return m1.year() === m2.year() && - m1.month() === m2.month() && - m1.date() === m2.date(); - } - - static getPeriodStart(tz: string): Date { - let m = moment().tz(tz || defaultTz); - m.date(1); - m.hours(0); - m.minutes(0); - m.seconds(0); - m.milliseconds(0); - - return m.toDate(); - } - - static getTimezones(): string[] { - let timezones = ['']; - return timezones.concat(moment.tz.names()); - } - - static getDefaultTimezone(): string { - return defaultTz; - } - static newGuid() { let arr = new Uint8Array(16); window.crypto.getRandomValues(arr); diff --git a/src/app/transaction/advancededit.ts b/src/app/transaction/advancededit.ts index 1d3bf04..3c27720 100644 --- a/src/app/transaction/advancededit.ts +++ b/src/app/transaction/advancededit.ts @@ -15,6 +15,7 @@ import { AbstractControl } from '@angular/forms'; import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; import { OrgService } from '../core/org.service'; import { TransactionService } from '../core/transaction.service'; @@ -50,7 +51,7 @@ export class AdvancedEdit { this.org = this.orgService.getCurrentOrg(); - let dateString = Util.getLocalDateString(item.tx.date, this.org.timezone); + let dateString = DateUtil.getLocalDateString(item.tx.date, this.org.timezone); this.form = new FormGroup({ date: new FormControl(dateString), @@ -110,9 +111,9 @@ export class AdvancedEdit { this.error = null; let date = this.item.tx.id ? this.item.tx.date : new Date(); - let formDate = Util.getDateFromLocalDateString(this.form.value.date, this.org.timezone); + let formDate = DateUtil.getDateFromLocalDateString(this.form.value.date, this.org.timezone); - date = Util.computeTransactionDate(formDate, date, this.org.timezone); + date = DateUtil.computeTransactionDate(formDate, date, this.org.timezone); let tx = new Transaction({ id: this.item.tx.id, diff --git a/src/app/transaction/list.ts b/src/app/transaction/list.ts index 21b160a..6a48a19 100644 --- a/src/app/transaction/list.ts +++ b/src/app/transaction/list.ts @@ -18,6 +18,7 @@ import { } from '@angular/forms'; import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/mergeMap'; import { AdvancedEdit } from './advancededit'; @@ -76,8 +77,6 @@ export class TxListPage implements OnInit, AfterViewChecked { this.accountId = this.route.snapshot.paramMap.get('id'); //+this.route.snapshot.paramMap.get('id'); this.org = this.orgService.getCurrentOrg(); - console.log(this.org); - this.accountService.getAccountTree().subscribe(tree => { this.account = tree.accountMap[this.accountId]; this.selectAccounts = tree.getFlattenedAccounts().filter(account => { @@ -95,7 +94,7 @@ export class TxListPage implements OnInit, AfterViewChecked { splits: [] }); - Util.setEndOfDay(newTx.date, this.org.timezone); + DateUtil.setEndOfDay(newTx.date, this.org.timezone); newTx.splits.push(new Split({ accountId: this.account.id @@ -410,7 +409,7 @@ export class TxListPage implements OnInit, AfterViewChecked { item.editing = true; - let dateString = Util.getLocalDateString(item.tx.date, this.org.timezone); + let dateString = DateUtil.getLocalDateString(item.tx.date, this.org.timezone); this.log.debug(item); let debit = this.getDebit(item); @@ -629,9 +628,9 @@ export class TxListPage implements OnInit, AfterViewChecked { } let date = item.tx.id ? item.tx.date : new Date(); - let formDate = Util.getDateFromLocalDateString(item.form.value.date, this.org.timezone); + let formDate = DateUtil.getDateFromLocalDateString(item.form.value.date, this.org.timezone); - date = Util.computeTransactionDate(formDate, date, this.org.timezone); + date = DateUtil.computeTransactionDate(formDate, date, this.org.timezone); let tx = new Transaction({ id: item.tx.id, @@ -714,7 +713,7 @@ export class TxListPage implements OnInit, AfterViewChecked { splits: [] }); - Util.setEndOfDay(newTx.date, this.org.timezone); + DateUtil.setEndOfDay(newTx.date, this.org.timezone); newTx.splits.push(new Split({ accountId: this.account.id @@ -832,11 +831,11 @@ export class TxListPage implements OnInit, AfterViewChecked { autocomplete(item: TxItem, tx: Transaction) { this.log.debug('chose tx', tx); - let formDate = Util.getDateFromLocalDateString(item.form.value.date, this.org.timezone); + let formDate = DateUtil.getDateFromLocalDateString(item.form.value.date, this.org.timezone); item.tx = new Transaction( { id: item.tx.id, - date: Util.computeTransactionDate(formDate, new Date(), this.org.timezone), + date: DateUtil.computeTransactionDate(formDate, new Date(), this.org.timezone), description: tx.description, splits: tx.splits } diff --git a/src/app/transaction/new.ts b/src/app/transaction/new.ts index 4defc4e..05b3c08 100644 --- a/src/app/transaction/new.ts +++ b/src/app/transaction/new.ts @@ -14,6 +14,7 @@ import { TransactionService } from '../core/transaction.service'; import { OrgService } from '../core/org.service'; import { Account, AccountApi, AccountTree } from '../shared/account'; import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; import { AppError } from '../shared/error'; import { Transaction, Split } from '../shared/transaction'; import { Logger } from '../core/logger'; @@ -62,7 +63,7 @@ export class NewTransactionPage { this.numAccountsShown = 3; this.org = this.orgService.getCurrentOrg(); - let dateString = Util.getLocalDateString(new Date(), this.org.timezone); + let dateString = DateUtil.getLocalDateString(new Date(), this.org.timezone); this.form = this.fb.group({ type: ['', Validators.required], firstAccountPrimary: [null, Validators.required], @@ -226,9 +227,9 @@ export class NewTransactionPage { this.error = null; let date = new Date(); - let formDate = Util.getDateFromLocalDateString(this.form.value.date, this.org.timezone); + let formDate = DateUtil.getDateFromLocalDateString(this.form.value.date, this.org.timezone); - date = Util.computeTransactionDate(formDate, date, this.org.timezone); + date = DateUtil.computeTransactionDate(formDate, date, this.org.timezone); let tx = new Transaction({ id: Util.newGuid(), From 1f2aff130bdcc25d9566e6824a3661e584c0bc20 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 27 Jun 2019 16:39:54 -0400 Subject: [PATCH 5/8] update copy to switch organization --- src/app/org/org.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/org/org.html b/src/app/org/org.html index cd60567..68cb22f 100644 --- a/src/app/org/org.html +++ b/src/app/org/org.html @@ -36,7 +36,7 @@ -

Choose Organization

+

Switch Organization

@@ -50,7 +50,7 @@

{{chooseOrgError.message}}

- +
From 3309178effa52b272def63447ff7e619c94d4788 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 27 Jun 2019 16:42:13 -0400 Subject: [PATCH 6/8] use smaller moment library --- src/app/shared/datetz.pipe.ts | 4 ++-- src/app/shared/dateutil.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/shared/datetz.pipe.ts b/src/app/shared/datetz.pipe.ts index df18164..213483f 100644 --- a/src/app/shared/datetz.pipe.ts +++ b/src/app/shared/datetz.pipe.ts @@ -1,6 +1,6 @@ import { Pipe, PipeTransform } from '@angular/core'; -//import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'; -import * as moment from 'moment-timezone'; +import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'; +//import * as moment from 'moment-timezone'; @Pipe({name: 'datetz'}) export class DateTzPipe implements PipeTransform { diff --git a/src/app/shared/dateutil.ts b/src/app/shared/dateutil.ts index 3625029..719a13c 100644 --- a/src/app/shared/dateutil.ts +++ b/src/app/shared/dateutil.ts @@ -1,5 +1,5 @@ -//import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'; -import * as moment from 'moment-timezone'; +import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'; +//import * as moment from 'moment-timezone'; const defaultTz = moment.tz.guess(); From 9ad7f1ff61787f0cc0cb88379b534226f66fa187 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 27 Jun 2019 16:53:47 -0400 Subject: [PATCH 7/8] update api version --- src/app/core/api.service.ts | 2 +- src/app/core/websocket.service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/api.service.ts b/src/app/core/api.service.ts index fd0650f..33c241a 100644 --- a/src/app/core/api.service.ts +++ b/src/app/core/api.service.ts @@ -22,7 +22,7 @@ export class ApiService { private httpOptions = { headers: new HttpHeaders({ 'content-type': 'application/json', - 'accept-version': '^1.0.1' + 'accept-version': '^1.3.0' }) }; private orgId: string; diff --git a/src/app/core/websocket.service.ts b/src/app/core/websocket.service.ts index 747ab54..eb7ff8e 100644 --- a/src/app/core/websocket.service.ts +++ b/src/app/core/websocket.service.ts @@ -10,7 +10,7 @@ import 'rxjs/add/operator/retryWhen'; import 'rxjs/add/operator/repeatWhen'; import 'rxjs/add/operator/delay'; -var version = '^1.0.1'; +var version = '^1.3.0'; @Injectable() export class WebSocketService { From ce66ad2ec57a5e848c4194ba89be7cbb61dab458 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Fri, 28 Jun 2019 14:35:46 -0400 Subject: [PATCH 8/8] update /orgs/new --- src/app/org/neworg.html | 8 ++++++++ src/app/org/neworg.ts | 7 +++++++ src/app/org/org.ts | 1 - 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/org/neworg.html b/src/app/org/neworg.html index fd9aa45..9db3078 100644 --- a/src/app/org/neworg.html +++ b/src/app/org/neworg.html @@ -33,6 +33,14 @@
+
+ + +
diff --git a/src/app/org/neworg.ts b/src/app/org/neworg.ts index 4ce4e38..f2a0d9a 100644 --- a/src/app/org/neworg.ts +++ b/src/app/org/neworg.ts @@ -12,6 +12,7 @@ import { OrgService } from '../core/org.service'; import { Org } from '../shared/org'; import { AppError } from '../shared/error'; import { Util } from '../shared/util'; +import { DateUtil } from '../shared/dateutil'; @Component({ selector: 'app-neworg', @@ -22,16 +23,22 @@ export class NewOrgPage { public error: AppError; public joinOrgForm: FormGroup; public joinOrgError: AppError; + public timezones: string[]; + public defaultTz: string; constructor( private log: Logger, private orgService: OrgService, private fb: FormBuilder ) { + this.timezones = DateUtil.getTimezones(); + this.defaultTz = DateUtil.getDefaultTimezone(); + this.form = fb.group({ 'name': ['', Validators.required], 'currency': ['USD', Validators.required], 'precision': [2, Validators.required], + 'timezone': [this.defaultTz, Validators.required], 'createDefaultAccounts': [true, Validators.required] }); diff --git a/src/app/org/org.ts b/src/app/org/org.ts index 2488e6c..188aeb9 100644 --- a/src/app/org/org.ts +++ b/src/app/org/org.ts @@ -46,7 +46,6 @@ export class OrgPage { this.timezones = DateUtil.getTimezones(); this.defaultTz = DateUtil.getDefaultTimezone(); - console.log('defaultTz', this.defaultTz); this.invites = null; this.updateOrgForm = fb.group({