use timezone everywhere

This commit is contained in:
Patrick Nagurny
2019-06-27 14:11:05 -04:00
parent ca871a8021
commit b602cb1740
21 changed files with 150 additions and 114 deletions

View File

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

View File

@@ -35,7 +35,7 @@
<form [id]="'form' + item.tx.id + item.activeSplitIndex" [formGroup]="item.form" *ngFor="let item of items; let i = index">
<div class="row" (click)="editTransaction(item, $event)" [ngClass]="{odd: !(i % 2), editing: item.editing}">
<div class="col custom-3 date">
<span *ngIf="!item.editing" class="date">{{item.tx.date | date:"M/d/y"}}</span>
<span *ngIf="!item.editing" class="date">{{item.tx.date | datetz:"M/D/YYYY":org.timezone}}</span>
<input *ngIf="item.editing" type="date" formControlName="date" placeholder="Date" class="form-control" (keyup.enter)="onEnter(item, $event)"/>
</div>
<div class="col custom-7 description">

View File

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

View File

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