Skip to content

Commit

Permalink
Merge branch 'dev-alex/date-utilstomoment'
Browse files Browse the repository at this point in the history
  • Loading branch information
jortilles committed Mar 21, 2024
2 parents 6f1ec52 + 8b02912 commit 58fb84a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


<ng-template #filterTemplate>
<p-card [header]="header1">
<p-card>
<div class="grid">
<div class="col-12">
<div class="grid">
Expand Down
184 changes: 75 additions & 109 deletions eda/eda_app/src/app/services/utils/date-utils.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

import { Injectable } from '@angular/core';
import moment from 'moment';


@Injectable()
export class DateUtils {

getDateFormatApp(date: any, ignoreTimeZone = true) {

}
Expand All @@ -26,6 +28,7 @@ export class DateUtils {
case 'monthFullPreviousYear': return this.setMonthFullPreviousYear();
case 'yearStart': return this.setYearStart();
case 'yearStartPreviousYear': return this.setYearStartPreviousYear();
case 'yearStartPreviousYearFull': return this.setYearStartPreviousYearFull();
case 'last3': return this.setLast3();
case 'last7': return this.setLast7();
case 'last15': return this.setLast15();
Expand All @@ -36,168 +39,131 @@ export class DateUtils {
}

public allDates(): Array<Date> {
return [new Date('1984-08-01'), new Date('2090-01-01')];
const mostOldDate = moment('1939-01-01').toDate();
const today = moment().toDate();
return [mostOldDate, today];
}

public setYesterday(): Array<Date> {
const d = new Date();
const yesterday = d.setDate(d.getDate() - 1);
return [new Date(yesterday), new Date(yesterday)]
const yesterday = moment().subtract(1,'days').toDate()
return [yesterday,yesterday];
}

public setBeforeYesterday(): Array<Date> {
const d = new Date();
const beforeYesterday = d.setDate(d.getDate() - 2);
return [new Date(beforeYesterday), new Date(beforeYesterday)]
const beforeYesterday = moment().subtract(2,'days').toDate();
return [beforeYesterday,beforeYesterday];
}

public setWeekStart(): Array<Date> {
const getMonday = (d: Date) => {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday
return new Date(d.setDate(diff));
}
const today = new Date();
const monday = getMonday(new Date());
return [monday, today];
const startOnMonday = moment().startOf('isoWeek').toDate();
const endOnFriday = moment().startOf('isoWeek').add(4,'days').toDate();
return [startOnMonday,endOnFriday];
}

public setWeekStartFull(): Array<Date> {
let getMonday = (d: Date) => {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday
return new Date(d.setDate(diff));
}
const today = new Date();
const monday = getMonday(new Date());
today.setDate( monday.getDate() + 6);
return [monday, today];
const startOnMonday = moment().startOf('isoWeek').toDate();
const endOnSunday = moment().startOf('isoWeek').add(6,'days').toDate();
return [startOnMonday, endOnSunday];
}

public setPastWeek(): Array<Date> {
const getMonday = (d: Date) => {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday
return new Date(d.setDate(diff));
}
let today = new Date();
today.setDate(today.getDate() - 7);
const monday = getMonday(today);
return [monday, today];
const pastWeekMonday = moment().subtract(1,'weeks').startOf('isoWeek').toDate();
const pastWeekFriday = moment().subtract(1,'weeks').startOf('isoWeek').add(4,'days').toDate();
return [pastWeekMonday, pastWeekFriday];
}

public setPastWeekFull(): Array<Date> {
const getMonday = (d: Date) => {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday
return new Date(d.setDate(diff));
}
let today = new Date();
today.setDate(today.getDate() - 7);
const monday = getMonday(today);
today.setDate( monday.getDate() + 6);
return [monday, today];
const pastWeekMonday = moment().subtract(1,'weeks').startOf('isoWeek').toDate();
const pastWeekSunday = moment().subtract(1,'weeks').startOf('isoWeek').add(6,'days').toDate();
return [pastWeekMonday, pastWeekSunday];
}



public setMonthStart(): Array<Date> {
const today = new Date();
const monthStart = new Date(today.getFullYear(), today.getMonth(), 1);
public setMonthStart(): Array<Date> {
const today = moment().toDate();
const monthStart = moment().startOf('month').toDate();
return [monthStart, today];
}

public setPastMonth(): Array<Date> {
const t = new Date();
var d = new Date();
var newMonth = d.getMonth() - 1;
if(newMonth < 0){
newMonth += 12;
d.setFullYear(d.getFullYear() - 1);
}
d.setMonth(newMonth);
const monthStart = new Date(d.getFullYear(), d.getMonth(), 1);
const monthEnd = new Date(d.getFullYear(), d.getMonth(), t.getDate() );

return [monthStart, monthEnd];
const monthStart = moment().subtract(1,'months').startOf('month').toDate();
const pastMonthDay = moment().subtract(1,'months').toDate();
return [monthStart, pastMonthDay];
}

public setPastMonthFull(): Array<Date> {
const t = new Date();
var d = new Date();
var newMonth = d.getMonth() - 1;
if(newMonth < 0){
newMonth += 12;
d.setFullYear(d.getFullYear() - 1);
}
d.setMonth(newMonth);
const monthStart = new Date(d.getFullYear(), d.getMonth(), 1);
const monthEnd = new Date(d.getFullYear(), d.getMonth(), new Date(d.getFullYear(), d.getMonth()+1, 0).getDate() );

const monthStart = moment().subtract(1,'months').startOf('month').toDate();
const monthEnd = moment().subtract(1,'months').endOf('month').toDate();
console.log("StartofMonth: ", monthStart)
console.log("EndOfMonth:", monthEnd);
return [monthStart, monthEnd];
}


public setMonthStartPreviousYear(): Array<Date> {
const t = new Date();
const today = new Date( t.getFullYear()-1, t.getMonth(), t.getDate());
const monthStart = new Date(today.getFullYear(), today.getMonth(), 1);
return [monthStart, today];
const monthStartPastYear = moment().subtract(1,'years').startOf('month').toDate();
const todayPastYear = moment().subtract(1,'years').toDate();
return [monthStartPastYear,todayPastYear];
}

public setMonthFullPreviousYear(): Array<Date> {
const t = new Date();
const monthStart = new Date(t.getFullYear()-1, t.getMonth(), 1);
const today = new Date( t.getFullYear()-1, t.getMonth(), new Date(t.getFullYear(), t.getMonth()+1, 0).getDate() );
return [monthStart, today];
const monthStartPastYear = moment().subtract(1,'years').startOf('month').toDate();
const monthEndPastYear = moment().subtract(1,'years').endOf('month').toDate();
return [monthStartPastYear,monthEndPastYear];
}

public setYearStart(): Array<Date> {
const today = new Date();
const yearStart = new Date(today.getFullYear(), 0, 1);

const yearStart = moment().startOf('year').toDate();
const today = moment().toDate();
return [yearStart, today];
}

public setYearStartPreviousYear(): Array<Date> {
const t = new Date();
const today = new Date( t.getFullYear()-1, t.getMonth(), t.getDate());
const yearStart = new Date(today.getFullYear(), 0, 1);
return [yearStart, today];
const pastYearStart = moment().subtract(1,'years').startOf('year').toDate();
const pastYearToday = moment().subtract(1,'years').toDate();
return [pastYearStart, pastYearToday];
}

public setYearStartPreviousYearFull(): Array<Date> {
const pastYearStart = moment().subtract(1,'years').startOf('year').toDate();
const pastYearEnd = moment().subtract(1,'years').endOf('year').toDate();
return [pastYearStart, pastYearEnd];
}

public setLast3(): Array<Date> {
const today = new Date();
const last3 = new Date(today.getTime() - (2 * 24 * 60 * 60 * 1000));
return [last3, today];
const today = moment().toDate();
const lastTwoDays = moment().subtract(2,'days').toDate();
return [lastTwoDays, today];
}

public setLast7(): Array<Date> {
const today = new Date();
const last7 = new Date(today.getTime() - (6 * 24 * 60 * 60 * 1000));
return [last7, today];
const today = moment().toDate();
const lastSixDays = moment().subtract(6,'days').toDate();
return [lastSixDays, today];
}

public setLast15(): Array<Date> {
const today = new Date();
const last15 = new Date(today.getTime() - (14 * 24 * 60 * 60 * 1000));
return [last15, today];
const today = moment().toDate();
const lastFourteenDays = moment().subtract(14,'days').toDate();
return [lastFourteenDays, today];
}

public setLast30(): Array<Date> {
const today = new Date();
const last15 = new Date(today.getTime() - (29 * 24 * 60 * 60 * 1000));
return [last15, today];
const today = moment().toDate();
const lastTwentyNine = moment().subtract(29,'days').toDate();
return [lastTwentyNine, today];
}

public setLast60(): Array<Date> {
const today = new Date();
const last15 = new Date(today.getTime() - (59 * 24 * 60 * 60 * 1000));
return [last15, today];
const today = moment().toDate();
const lastFiftyNine = moment().subtract(59,'days').toDate();
return [lastFiftyNine, today];
}

public setLast120(): Array<Date> {
const today = new Date();
const last15 = new Date(today.getTime() - (119 * 24 * 60 * 60 * 1000));
return [last15, today];
const today = moment().toDate();
const lastOneHudredNineteen = moment().subtract(119,'days').toDate();
return [lastOneHudredNineteen, today];
}

public rangeToString(range: Array<Date>): Array<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class EdaDatePickerComponent implements OnChanges {
{ label: $localize`:@@DatePickerMonthPreviousYearFull:Éste mes al completo del año pasado`, value: 'monthFullPreviousYear' },
{ label: $localize`:@@DatePickerYear:Éste año`, value: 'yearStart' },
{ label: $localize`:@@DatePickerYearPreviousYear:El año pasado`, value: 'yearStartPreviousYear' },
{ label: $localize`:@@DatePickerYearPreviousYearFull:El año pasado, completo`, value: 'yearStartPreviousYearFull' },
{ label: $localize`:@@DatePickerLast3:Últimos 3 días`, value: 'last3' },
{ label: $localize`:@@DatePickerLast7:Últimos 7 días`, value: 'last7' },
{ label: $localize`:@@DatePickerLast15:Últimos 15 días`, value: 'last15' },
Expand Down
4 changes: 4 additions & 0 deletions eda/eda_app/src/locale/messages.ca.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,10 @@ Entrar<x id="CLOSE_BOLD_TEXT" ctype="x-b" equiv-text="&lt;/b&gt;"/>
<source>El año pasado</source>
<target>L'any passat</target>
</trans-unit>
<trans-unit id="DatePickerYearPreviousYearFull">
<source>El año pasado, completo</source>
<target>L'any passat, complet</target>
</trans-unit>
<trans-unit id="DatePickerLast7">
<source> Últimos 7 días </source>
<target>Últims 7 dies </target>
Expand Down
4 changes: 4 additions & 0 deletions eda/eda_app/src/locale/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2805,6 +2805,10 @@ Login<x id="CLOSE_BOLD_TEXT" ctype="x-b" equiv-text="&lt;/b&gt;"/>
<source>El año pasado</source>
<target>Last year</target>
</trans-unit>
<trans-unit id="DatePickerYearPreviousYearFull">
<source>El año pasado, completo</source>
<target>Last year, the whole year</target>
</trans-unit>
<trans-unit id="DatePickerLast7">
<source> Últimos 7 días </source>
<target>Last 7 days </target>
Expand Down
4 changes: 4 additions & 0 deletions eda/eda_app/src/locale/messages.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2787,6 +2787,10 @@ Login<x id="CLOSE_BOLD_TEXT" ctype="x-b" equiv-text="&lt;/b&gt;"/>
<source>El año pasado</source>
<target>Zeszły rok</target>
</trans-unit>
<trans-unit id="DatePickerYearPreviousYearFull">
<source>El año pasado, completo</source>
<target>W zeszłym roku, kompletne</target>
</trans-unit>
<trans-unit id="DatePickerLast7">
<source> Últimos 7 días </source>
<target>Ostatnie 7 dni </target>
Expand Down

0 comments on commit 58fb84a

Please sign in to comment.