-
Notifications
You must be signed in to change notification settings - Fork 0
/
petronoticias.js
76 lines (62 loc) · 1.84 KB
/
petronoticias.js
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
function postProcess(output, input) {
let currentDate = new Date();
const parseDate = (dateTimeStr) => {
if(dateTimeStr) {
let date, time, day, month, year, hours, minutes, rest, monthYear, ampm, fullTime;
// "pubdate": "28. mar, 2018 às 6:49 pm 0 Comentários",
let dateTime = dateTimeStr.split(' ')[0];
[date, fullTime] = dateTime.split(' às ');
[day, monthYear] = date.split('.');
monthYear = monthYear.replace(' ', '');
[ month, year ] = monthYear.split(',');
// [time, ampm] = time.split(' ');
// [hours, minutes] = fullTime.split(':');
let hoursAndMinutes = `${fullTime} GMT-0200`;
let correctedDate = `${parseMonth(month)}/${day}/${year}`;
let dateTime = `${correctedDate} ${hoursAndMinutes}`;
return new Date(dateTime).toString();
}
return currentDate.toString();
}
var processedArticles = output.data.articles.map(
article => {
let pubdate = parseDate(article.pubdate);
article.pubdate = pubdate;
article.date = currentDate.toString();
article.valid = true;
article.summary = article.summary;
return article;
});
output.data.articles = processedArticles;
return output;
const parseMonth = (monthPT) => {
switch(monthPT.toLowerCase()) {
case 'jan':
return 1;
case 'fev':
return 2;
case 'mar':
return 3;
case 'abr':
return 4;
case 'mai':
return 5;
case 'jun':
return 6;
case 'jul':
return 7;
case 'ago':
return 8;
case 'set':
return 9;
case 'out':
return 10;
case 'nov':
return 11;
case 'dez':
return 12;
default:
return 1 + new Date().getMonth();
}
}
}