Skip to content

Commit 549d79c

Browse files
committed
Changed LocalDate to LocalDateTime for better sorting
1 parent a317bf7 commit 549d79c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/main/java/com/olegshan/entity/Job.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import javax.persistence.Column;
44
import javax.persistence.Entity;
55
import javax.persistence.Id;
6-
import java.time.LocalDate;
6+
import java.time.LocalDateTime;
77
import java.time.format.DateTimeFormatter;
88

99
/**
@@ -15,18 +15,18 @@ public class Job {
1515
@Id
1616
private String url;
1717
private String title;
18-
// @Column(length = Integer.MAX_VALUE)
18+
// Max value for PostgreSQL
1919
@Column(length = 10485760)
2020
private String description;
2121
private String company;
2222
private String source;
23-
private LocalDate date;
23+
private LocalDateTime date;
2424
private String dateToDisplay;
2525

2626
public Job() {
2727
}
2828

29-
public Job(String title, String description, String company, String source, String url, LocalDate date) {
29+
public Job(String title, String description, String company, String source, String url, LocalDateTime date) {
3030
this.title = title;
3131
this.description = description;
3232
this.company = company;
@@ -75,11 +75,11 @@ public void setUrl(String url) {
7575
this.url = url;
7676
}
7777

78-
public LocalDate getDate() {
78+
public LocalDateTime getDate() {
7979
return date;
8080
}
8181

82-
public void setDate(LocalDate date) {
82+
public void setDate(LocalDateTime date) {
8383
this.date = date;
8484
}
8585

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import java.io.IOException;
1717
import java.time.LocalDate;
18+
import java.time.LocalDateTime;
19+
import java.time.LocalTime;
1820

1921
/**
2022
* Created by olegshan on 03.10.2016.
@@ -55,7 +57,7 @@ public void parse(JobService jobService,
5557
String title = titleBlock.text();
5658
String description = job.getElementsByAttributeValue(descriptionData[0], descriptionData[1]).text();
5759
String company = getCompany(jobService, job, url, companyData);
58-
LocalDate date = getDate(jobService, url, dateData, titleBlock, job);
60+
LocalDateTime date = getDate(jobService, url, dateData, titleBlock, job);
5961

6062
Job parsedJob = new Job(title, description, company, siteName, url, date);
6163
jobRepository.save(parsedJob);
@@ -111,8 +113,8 @@ private Elements getTitleBlock(JobService jobService, Element job, String[] titl
111113
return titleBlock;
112114
}
113115

114-
private LocalDate getDate(JobService jobService, String url, String[] dateData, Elements titleBlock, Element job) {
115-
LocalDate date;
116+
private LocalDateTime getDate(JobService jobService, String url, String[] dateData, Elements titleBlock, Element job) {
117+
LocalDateTime date;
116118
String dateLine;
117119
if (jobService instanceof DouService) {
118120
Document dateDoc = getDoc(url);
@@ -131,7 +133,7 @@ private LocalDate getDate(JobService jobService, String url, String[] dateData,
131133
return date;
132134
}
133135

134-
private LocalDate getDateByLine(JobService jobService, String dateLine) {
136+
private LocalDateTime getDateByLine(JobService jobService, String dateLine) {
135137
String[] dateParts;
136138
int year;
137139
int month;
@@ -155,10 +157,10 @@ private LocalDate getDateByLine(JobService jobService, String dateLine) {
155157
if (jobService instanceof DouService || jobService instanceof HeadHunterService) {
156158
month = MonthsTools.MONTHS.get(dateParts[1].toLowerCase());
157159
} else month = Integer.parseInt(dateParts[1]);
158-
return LocalDate.of(year, month, day);
160+
return LocalDate.of(year, month, day).atTime(LocalTime.now());
159161
}
160162

161-
private LocalDate getDateForRabotaUa(String url) {
163+
private LocalDateTime getDateForRabotaUa(String url) {
162164
/*
163165
* There are several problems here.
164166
* First: there are two types of date tags, used on the site on different pages: "d-date" and "datePosted".
@@ -181,7 +183,7 @@ private LocalDate getDateForRabotaUa(String url) {
181183
dateLine = dateDoc.getElementsByAttributeValue("itemprop", "datePosted").text();
182184
if (dateLine.length() == 0) {
183185
//no date at all, sometimes it happens
184-
return LocalDate.now();
186+
return LocalDateTime.now();
185187
}
186188
}
187189
try {
@@ -199,7 +201,7 @@ private LocalDate getDateForRabotaUa(String url) {
199201
month = Integer.parseInt(dateParts[1]);
200202
day = Integer.parseInt(dateParts[2]);
201203
}
202-
return LocalDate.of(year, month, day);
204+
return LocalDate.of(year, month, day).atTime(LocalTime.now());
203205
}
204206

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

0 commit comments

Comments
 (0)