separate out date functions

This commit is contained in:
Patrick Nagurny
2019-06-27 16:37:46 -04:00
parent 5b720b79c4
commit 714a1b187b
12 changed files with 220 additions and 216 deletions

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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(),