good time

This commit is contained in:
Tykayn 2024-01-20 23:53:42 +01:00 committed by tykayn
parent e76ef0b241
commit 95be931ec8
2 changed files with 76 additions and 35 deletions

View File

@ -101,7 +101,7 @@
{{ subjects[currentSubjectId].title }} {{ subjects[currentSubjectId].title }}
</h1> </h1>
<p>{{ subjects[currentSubjectId].duration }} min, par {{ subjects[currentSubjectId].author }}</p> <p>{{ subjects[currentSubjectId].duration }} min, par {{ subjects[currentSubjectId].author }}</p>
<p>Reste: {{ countRemainingMinutes(subjects[currentSubjectId]) }} min</p> <!-- <p>Reste: {{ countRemainingMinutes(subjects[currentSubjectId]) }} min</p>-->
<div class="actions"> <div class="actions">
@ -120,9 +120,35 @@
<button class="btn btn-primary" (click)="updateProgressEveryPeriod()"> <button class="btn btn-primary" (click)="updateProgressEveryPeriod()">
up temps up temps
</button> </button>
<br>
<br>
<br>
<div class="timeseries">
topic duration:<br> {{subjects[currentSubjectId].duration}} min
topic start:<br>
{{subjects[currentSubjectId].startDate| date: 'HH:mm'}}
<br>
topic end:<br>
{{subjects[currentSubjectId].endDate| date: 'HH:mm'}}
<br>
temps passé:
{{round(subjects[currentSubjectId].spentSeconds)}}
<br>
secondes max:
{{
Math.floor(
getSecondsBetweenTwoDates(
null,
subjects[currentSubjectId].endDate
)
- subjects[currentSubjectId].spentSeconds
)
}}
</div>
</div> </div>
<p>avancement: {{ getPercentProgressTimeForTopic(subjects[currentSubjectId]) }} %</p>
<!-- <p>avancement: {{ getPercentProgressTimeForTopic(subjects[currentSubjectId]) }} %</p>-->
</div> </div>
<div class="stats"> <div class="stats">
<h2> <h2>

View File

@ -45,6 +45,7 @@ export class AppComponent implements OnInit, OnDestroy {
statsExplication: string = '' statsExplication: string = ''
hints: string = ""; hints: string = "";
Math:Math = Math
showDebug: boolean = true; showDebug: boolean = true;
startDate: Date = new Date(); startDate: Date = new Date();
@ -52,7 +53,6 @@ export class AppComponent implements OnInit, OnDestroy {
private topicChangeDate: Date = new Date(); private topicChangeDate: Date = new Date();
updateTopicChangeDate(): void { updateTopicChangeDate(): void {
const currentTime = new Date(); const currentTime = new Date();
const timeDifferenceInMilliseconds = this.topicChangeDate.getTime() - currentTime.getTime(); const timeDifferenceInMilliseconds = this.topicChangeDate.getTime() - currentTime.getTime();
@ -81,19 +81,20 @@ export class AppComponent implements OnInit, OnDestroy {
topics.forEach((topic: string) => { topics.forEach((topic: string) => {
let boom = topic.split('-') let boom = topic.split('-')
if (boom[0]) { if (boom[0]) {
accumulatedDuration += this.findMinutesDurationInDescription(topic) | 0 let duration = this.findMinutesDurationInDescription(topic) | 0
accumulatedDuration += duration
newTopics.push({ newTopics.push({
id: ii, id: ii,
title: boom[0], title: boom[0],
duration: 15, duration: duration,
spentSeconds: 0, spentSeconds: 0,
author: this.findAuthorInDescription(topic), author: this.findAuthorInDescription(topic),
notes: '', notes: '',
finished: false, finished: false,
startDate: this.getStartDateAfterDuration(accumulatedDuration + ''), startDate: this.getEndDateAfterDuration(accumulatedDuration, this.startDate),
endDate: this.getEndDateAfterDuration(accumulatedDuration + ''), endDate: this.getEndDateAfterDuration(duration + accumulatedDuration, this.startDate),
}) })
} }
ii += 1; ii += 1;
@ -110,11 +111,15 @@ export class AppComponent implements OnInit, OnDestroy {
* @param {string} [minute='00'] - A string representation of the minute (00-59). * @param {string} [minute='00'] - A string representation of the minute (00-59).
* @returns {Date} A new Date object set to the specified time. * @returns {Date} A new Date object set to the specified time.
*/ */
makeDateFromHourToday(hourInput: string, minuteInput: string = '00') { makeDateFromHourToday(hourInput: string){
let [hour, minute] = hourInput.split(":"); let [hour, minute] = hourInput.split(":");
let date = new Date(); let date = new Date();
if (!minute) {
return date;
}
date.setHours(parseInt(hour)); date.setHours(parseInt(hour));
date.setMinutes(minuteInput ? parseInt(minuteInput) : parseInt(minute)); date.setMinutes(parseInt(minute));
console.log('hourInput', hourInput, date)
return date; return date;
} }
@ -137,8 +142,8 @@ export class AppComponent implements OnInit, OnDestroy {
ngOnInit() { ngOnInit() {
this.parseTheListOfTopicsInPasteLand() this.parseTheListOfTopicsInPasteLand()
this.startDate = this.makeDateFromHourToday(this.startTime + ''); this.startDate = this.makeDateFromHourToday(this.startTime);
this.endDate = this.makeDateFromHourToday(this.endTime + ''); this.endDate = this.makeDateFromHourToday(this.endTime);
} }
@ -163,11 +168,12 @@ export class AppComponent implements OnInit, OnDestroy {
return 0; return 0;
} }
private getEndDateAfterDuration(accumulatedDuration: string) { private getEndDateAfterDuration(minutes: number, startDate: Date) {
return this.makeDateFromHourToday(accumulatedDuration)
return new Date(startDate.getTime() + minutes * 60000);
} }
private getStartDateAfterDuration(accumulatedDuration: string) { getStartDateAfterDuration(accumulatedDuration: string) {
return this.makeDateFromHourToday(accumulatedDuration) return this.makeDateFromHourToday(accumulatedDuration)
} }
@ -183,6 +189,8 @@ export class AppComponent implements OnInit, OnDestroy {
getPercentProgressTimeForTopic(topic: Topic) { getPercentProgressTimeForTopic(topic: Topic) {
let now = new Date(); let now = new Date();
console.log('topic démarré', topic.startDate.getTime())
console.log('topic va se finir', topic.endDate.getTime(), topic.endDate.getTime() - topic.startDate.getTime())
return Math.floor((now.getTime() - topic.startDate.getTime()) / (topic.endDate.getTime() - topic.startDate.getTime()) * 100); return Math.floor((now.getTime() - topic.startDate.getTime()) / (topic.endDate.getTime() - topic.startDate.getTime()) * 100);
} }
@ -347,7 +355,14 @@ export class AppComponent implements OnInit, OnDestroy {
lien.click(); lien.click();
} }
getMinutesBetweenTwoDates(date1: Date, date2: Date) { getMinutesBetweenTwoDates(date1: Date = new Date(), date2: Date) {
return Math.floor((date2.getTime() - date1.getTime()) / 60000); return Math.floor((date2.getTime() - date1.getTime()) / 60000);
} }
getSecondsBetweenTwoDates(date1: Date | null, date2: Date) {
if (!date1) {
date1 = new Date()
}
return Math.floor((date2.getTime() - date1.getTime()) / 1000);
}
} }