Skip to content

Commit 00c6a2c

Browse files
committed
Forced LocalDateTime to use 24-hours format for correct sorting
1 parent 17209a7 commit 00c6a2c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/java/com/olegshan/parser/Parser.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import java.time.LocalDate;
1818
import java.time.LocalDateTime;
1919
import java.time.LocalTime;
20+
import java.time.temporal.ChronoField;
2021

2122
/**
2223
* Created by olegshan on 03.10.2016.
2324
*/
2425
@Component
2526
public class Parser {
2627

28+
private static final int HOUR = LocalDateTime.now().get(ChronoField.HOUR_OF_DAY);
2729
@Autowired
2830
private JobRepository jobRepository;
2931

@@ -61,7 +63,7 @@ public void parse(JobService jobService,
6163
}
6264

6365
private Document getDoc(String siteToParse) {
64-
Document doc = null;
66+
Document doc;
6567
try {
6668
doc = Jsoup.connect(siteToParse).userAgent("Mozilla").timeout(0).get();
6769
} catch (IOException e) {
@@ -160,7 +162,7 @@ private LocalDateTime getDateByLine(JobService jobService, String dateLine) {
160162
if (jobService instanceof DouService || jobService instanceof HeadHunterService) {
161163
month = MonthsTools.MONTHS.get(dateParts[1].toLowerCase());
162164
} else month = Integer.parseInt(dateParts[1]);
163-
return LocalDate.of(year, month, day).atTime(LocalTime.now());
165+
return LocalDate.of(year, month, day).atTime(LocalTime.of(HOUR, 0, 0));
164166
}
165167

166168
private LocalDateTime getDateForRabotaUa(String url) {
@@ -204,7 +206,7 @@ private LocalDateTime getDateForRabotaUa(String url) {
204206
month = Integer.parseInt(dateParts[1]);
205207
day = Integer.parseInt(dateParts[2]);
206208
}
207-
return LocalDate.of(year, month, day).atTime(LocalTime.now());
209+
return LocalDate.of(year, month, day).atTime(LocalTime.of(HOUR, 0, 0));
208210
}
209211

210212
private String getCompany(JobService jobService, Element job, String url, String[] companyData) {

0 commit comments

Comments
 (0)