Fix autour des dates.
This commit is contained in:
26
Front/skydivelogs-app/src/services/dateService.ts
Normal file
26
Front/skydivelogs-app/src/services/dateService.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class DateService {
|
||||
private milliSeconInDay: number;
|
||||
|
||||
constructor() {
|
||||
this.milliSeconInDay = 1000 * 60 * 60 * 24;
|
||||
}
|
||||
|
||||
public AddDays(currentDate: Date, nbDays: number): Date {
|
||||
const totalMilliSeconds = nbDays * this.milliSeconInDay;
|
||||
const currentTime = currentDate.getTime();
|
||||
|
||||
currentDate.setTime(currentTime + totalMilliSeconds);
|
||||
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
public DiffBetweenDates(beginDate: Date, endDate: Date): number {
|
||||
const diffInTime = endDate.getTime() - beginDate.getTime();
|
||||
const diffInDays = Math.round(diffInTime / (1000 * 3600 * 24));
|
||||
|
||||
return diffInDays;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { DropZoneResp } from "../models/dropzone";
|
||||
import { JumpResp } from "../models/jump";
|
||||
import { AircraftResp } from "../models/aircraft";
|
||||
import { JumpTypeResp } from "../models/jumpType";
|
||||
import { DropZoneResp } from '../models/dropzone';
|
||||
import { JumpResp } from '../models/jump';
|
||||
import { AircraftResp } from '../models/aircraft';
|
||||
import { JumpTypeResp } from '../models/jumpType';
|
||||
import {
|
||||
StatsResp,
|
||||
StatsByDzResp,
|
||||
@@ -14,15 +14,15 @@ import {
|
||||
StatsByJumpTypeResp,
|
||||
StatsByRigResp,
|
||||
StatsByYearResp
|
||||
} from "../models/statsresp";
|
||||
import { environment } from "../environments/environment";
|
||||
} from '../models/statsresp';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
@Injectable()
|
||||
export class ServiceApiGet {
|
||||
private readonly headers = new HttpHeaders({
|
||||
"Access-Control-Allow-Origin": environment.urlApi
|
||||
'Access-Control-Allow-Origin': environment.urlApi
|
||||
});
|
||||
constructor(private http: HttpClient) {}
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
public getListOfDropZones(): Observable<Array<DropZoneResp>> {
|
||||
return this.http
|
||||
|
||||
@@ -1,17 +1,65 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
|
||||
import { JumpReq } from "../models/jump";
|
||||
import { environment } from "../environments/environment";
|
||||
import { JumpReq } from '../models/jump';
|
||||
import { environment } from '../environments/environment';
|
||||
import { DateService } from './dateService';
|
||||
|
||||
@Injectable()
|
||||
export class ServiceApiPost {
|
||||
private readonly headers = new HttpHeaders({
|
||||
"Access-Control-Allow-Origin": environment.urlApi
|
||||
'Access-Control-Allow-Origin': environment.urlApi
|
||||
});
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
public AddJumps(
|
||||
constructor(private http: HttpClient,
|
||||
private dateService: DateService) { }
|
||||
|
||||
public AddListOfJump(
|
||||
selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedRig: number,
|
||||
withCutaway: boolean,
|
||||
beginDate: Date,
|
||||
endDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number
|
||||
) {
|
||||
const diffInDays = this.dateService.DiffBetweenDates(beginDate, endDate) + 1;
|
||||
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
|
||||
|
||||
for (let i = 1; beginDate.getTime() < endDate.getTime(); i++) {
|
||||
this.AddJumps(
|
||||
selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
countOfJumpsPerDay
|
||||
);
|
||||
|
||||
beginDate = this.dateService.AddDays(beginDate, 1);
|
||||
}
|
||||
|
||||
const restfJumps = countOfJumps - countOfJumpsPerDay * (diffInDays - 1);
|
||||
this.AddJumps(
|
||||
selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
restfJumps
|
||||
);
|
||||
}
|
||||
|
||||
private AddJumps(
|
||||
selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
@@ -31,7 +79,7 @@ export class ServiceApiPost {
|
||||
exitAltitude: defaultExitAltitude,
|
||||
deployAltitude: defaultDeployAltitude,
|
||||
gearId: selectedRig,
|
||||
notes: "",
|
||||
notes: '',
|
||||
id: 0,
|
||||
jumpDate: jumpDate
|
||||
};
|
||||
@@ -43,51 +91,4 @@ export class ServiceApiPost {
|
||||
// .subscribe(data => console.log(data));
|
||||
}
|
||||
}
|
||||
|
||||
public AddListOfJump(
|
||||
selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedRig: number,
|
||||
withCutaway: boolean,
|
||||
beginDate: Date,
|
||||
endDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number
|
||||
) {
|
||||
const diffInTime = endDate.getTime() - beginDate.getTime();
|
||||
const diffInDays = Math.round(diffInTime / (1000 * 3600 * 24));
|
||||
|
||||
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
|
||||
let temp: Date = beginDate;
|
||||
for (let i = 1; temp.getDate() < endDate.getDate(); i++) {
|
||||
this.AddJumps(
|
||||
selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
temp,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
countOfJumpsPerDay
|
||||
);
|
||||
|
||||
temp.setDate(temp.getDate() + 1);
|
||||
}
|
||||
|
||||
const restfJumps = countOfJumps - countOfJumpsPerDay * (diffInDays - 1);
|
||||
this.AddJumps(
|
||||
selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
restfJumps
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user