-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil-date.js
More file actions
137 lines (123 loc) · 4.57 KB
/
Copy pathutil-date.js
File metadata and controls
137 lines (123 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
const fs = require('fs-extra');
const paths = require('./paths');
const fechaFirmaTxtPath = paths.getFechaFirmaTxtPath();
const fechaEmisionTxtPath = paths.getFechaEmisionTxtPath();
const fechaVencimientoTxtPath = paths.getFechaVencimientoTxtPath();
const fechaDesdeTxtPath = paths.getFechaDesdeTxtPath();
const fechaHastaTxtPath = paths.getFechaHastaTxtPath();
function getTodayDteFormattedDate() {
return getDteFormattedDate(new Date());
}
function getDesdeDteFormattedDate() {
// const desdeDate = new Date();
// if (desdeDate.getDate() <= 20) desdeDate.setMonth(desdeDate.getMonth() - 2);
// else desdeDate.setMonth(desdeDate.getMonth() - 1);
// desdeDate.setDate(25);
// return getDteFormattedDate(desdeDate);
// const fechaVencimiento = fs.readFileSync(fechaVencimientoTxtPath, 'utf8');
// const desdeDate = new Date(fechaVencimiento);
// if (desdeDate.getDate() < 10) {
// desdeDate.setMonth(desdeDate.getMonth() - 3);
// } else {
// desdeDate.setMonth(desdeDate.getMonth() - 2);
// }
// desdeDate.setDate(25);
// return getDteFormattedDate(desdeDate);
return fs.readFileSync(fechaDesdeTxtPath, 'utf8');
}
function getHastaDteFormattedDate() {
// const hastaDate = new Date();
// if (hastaDate.getDate() <= 20) hastaDate.setMonth(hastaDate.getMonth() - 1);
// hastaDate.setDate(24);
// return getDteFormattedDate(hastaDate);
// const fechaVencimiento = fs.readFileSync(fechaVencimientoTxtPath, 'utf8');
// const hastaDate = new Date(fechaVencimiento);
// if (hastaDate.getDate() < 10) {
// hastaDate.setMonth(hastaDate.getMonth() - 2);
// } else {
// hastaDate.setMonth(hastaDate.getMonth() - 1);
// }
// hastaDate.setDate(24);
// return getDteFormattedDate(hastaDate);
return fs.readFileSync(fechaHastaTxtPath, 'utf8');
}
function getExpiryDteFormattedDate() {
// const expiryDate = new Date();
// if (expiryDate.getDate() > 20) expiryDate.setMonth(expiryDate.getMonth() + 1);
// expiryDate.setDate(20);
// return getDteFormattedDate(expiryDate);
return fs.readFileSync(fechaVencimientoTxtPath, 'utf8');
}
function getIssueDteFormattedDate() {
// const issueDate = new Date();
// if (issueDate.getDate() > 20) issueDate.setMonth(issueDate.getMonth() + 1);
// issueDate.setDate(0);
// return getDteFormattedDate(issueDate);
return fs.readFileSync(fechaEmisionTxtPath, 'utf8');
}
function getDteFormattedDate(date) {
return new Intl.DateTimeFormat('sv-SE', {
dateStyle: 'short',
timeZone: 'America/Santiago',
}).format(date);
}
function getTedFormattedTimeStamp() {
const tedDate = new Date();
// if (tedDate.getDate() >= 10 && tedDate.getDate() <= 20) tedDate.setDate(9);
// const date = new Intl.DateTimeFormat('sv-SE', {
// dateStyle: 'short',
// timeZone: 'America/Santiago',
// }).format(tedDate);
const date = fs.readFileSync(fechaFirmaTxtPath, 'utf8');
const time = new Intl.DateTimeFormat('sv-SE', {
timeStyle: 'medium',
timeZone: 'America/Santiago',
}).format(tedDate);
return `${date}T${time}`;
}
function getFormattedTimeStamp() {
const today = new Date();
const date = getTodayDteFormattedDate();
const hour = String(today.getHours()).padStart(2, 0);
const minutes = String(today.getMinutes()).padStart(2, 0);
const seconds = String(today.getSeconds()).padStart(2, 0);
// const time = new Intl.DateTimeFormat('sv-SE', {
// timeStyle: 'medium',
// timeZone: 'America/Santiago',
// }).format(today);
return `${date}T${hour}_${minutes}_${seconds}`;
}
function getChartMonths() {
let currentDate = new Date();
const chartDateArray = [];
for (let i = 0; i < 13; i++) {
const date = new Date(currentDate.getFullYear(), currentDate.getMonth() - i, 1);
const month = new Intl.DateTimeFormat('es-ES', { month: 'short' }).format(date).slice(0, 3).toUpperCase();
const year = date.getFullYear();
chartDateArray.push(`${month}-${year}`);
}
return chartDateArray;
}
function getChartPreviousMonths() {
let currentDate = new Date();
const chartDateArray = [];
for (let i = 0; i < 13; i++) {
const date = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1 - i, 1);
const month = new Intl.DateTimeFormat('es-ES', { month: 'short' }).format(date).slice(0, 3).toUpperCase();
const year = date.getFullYear();
chartDateArray.push(`${month}-${year}`);
}
return chartDateArray;
}
module.exports = {
getTodayDteFormattedDate,
getExpiryDteFormattedDate,
getTedFormattedTimeStamp,
getFormattedTimeStamp,
getIssueDteFormattedDate,
getDesdeDteFormattedDate,
getHastaDteFormattedDate,
getChartMonths,
getChartPreviousMonths,
};