Skip to content

Commit

Permalink
BRE: time parsing for br market
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesasaurus committed May 30, 2020
1 parent aee2983 commit d3ba838
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Scrape/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TwCheeseDate } from '/twcheese/src/Models/TwCheeseDate.js';
*/
function parseArrival(text, market) {
switch (market) {
case 'br': return parseArrivalBrazilianPortuguese(text);
case 'cz': return parseArrivalCzech(text);
case 'pt': return parseArrivalPortuguese(text);
}
Expand Down Expand Up @@ -39,4 +40,12 @@ function parseArrivalPortuguese(text) {
return TwCheeseDate.newServerDate(year, month, day, hours, minutes, seconds, millis || 0);
}

function parseArrivalBrazilianPortuguese(text) {
// e.g. "mai 20, 2020 11:54:33:503"
let expr = /(\D+) (\d+), (\d+) (\d+):(\d+):(\d+):?(\d+)?/;
let [, monthName, day, year, hours, minutes, seconds, millis] = text.match(expr);
let month = ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'].indexOf(monthName.toLowerCase());
return TwCheeseDate.newServerDate(year, month, day, hours, minutes, seconds, millis || 0);
}

export { parseArrival };
28 changes: 28 additions & 0 deletions test/unit/Scrape/time/parseArrival.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,32 @@ describe('parseArrival', function() {
assertServerTime(expected, actual);
});

it('should handle br format', function() {
let actual = parseArrival('mai 20, 2020 11:54:33:503', 'br');
let expected = {
year: 2020,
month: 4,
date: 20,
hours: 11,
minutes: 54,
seconds: 33,
millis: 503
};
assertServerTime(expected, actual);
});

it('should handle br format with millis disabled', function() {
let actual = parseArrival('mai 20, 2020 11:54:33', 'br');
let expected = {
year: 2020,
month: 4,
date: 20,
hours: 11,
minutes: 54,
seconds: 33,
millis: 0
};
assertServerTime(expected, actual);
});

});

2 comments on commit d3ba838

@natanprog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cheesasaurus

I don't know, if this is the right place to give feedback

Captura de tela_2020-05-30_09-36-53
Captura de tela_2020-05-30_09-38-23

But for some reason, it is misidentifying the name of the month

result:
Launched dez. 26, 2019 20:24:10:571 Returns jan. 02, 2020 16:01:12:000

how it should be:
Launched mai. 26, 2019 20:24:10:571 Returns jun. 02, 2020 16:01:12:000

_and I'm sorry for bothering you (I saw in the other message that you don't play anymore)

and thanks!_

@cheesasaurus
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natanprog

I don't know, if this is the right place to give feedback

Creating an issue would be the best way for me to keep track of it.
I added one here: #67

Please sign in to comment.