source: PerfectFit/Dialog/src/test/java/movingdialog/dateParseTest.java@ 7

Last change on this file since 7 was 7, checked in by Wouter Pasman, 9 months ago

#124 release PerfectFit sources

File size: 1.3 KB
Line 
1package movingdialog;
2
3import java.text.ParseException;
4import java.time.LocalDate;
5import java.time.ZoneId;
6import java.time.format.DateTimeFormatter;
7
8import org.junit.Ignore;
9import org.junit.Test;
10
11public class dateParseTest {
12// LocalDate date1 = LocalDate.of(2021, 12, 17); // dec 17 2021
13// LocalDate date2 = LocalDate.of(2021, 1, 7); // jan 7
14
15 @Test
16 public void parseDateTest1() throws ParseException {
17 System.out.println(getSeconds("17 12 2021", "d M y"));
18 System.out.println(getSeconds("7 1 2021", "d M y"));
19 System.out.println(getSeconds("7 1 21", "d M y"));
20 }
21
22 @Test
23 public void parseDateTest2() throws ParseException {
24 System.out.println(getSeconds("17-12-2021", "d-M-y"));
25 System.out.println(getSeconds("7-1-2021", "d-M-y"));
26 System.out.println(getSeconds("7-1-21", "d-M-y"));
27 }
28
29 /**
30 * Maybe if we can figure out how this parser pareses NAMES of month...
31 */
32 @Ignore
33 @Test
34 public void parseDateTest3() throws ParseException {
35 System.out.println(getSeconds("17 dec 2021", "d LLL y"));
36 }
37
38 private double getSeconds(String date, String format) {
39 DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
40
41 return LocalDate.parse(date, formatter)
42 .atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli()
43 / 1000d;
44
45 }
46}
Note: See TracBrowser for help on using the repository browser.