File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
main/java/io/github/benas/unixstream
test/java/io/github/benas/unixstream/components Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 5
5
import java .io .*;
6
6
import java .nio .file .*;
7
7
import java .time .LocalDate ;
8
+ import java .time .temporal .WeekFields ;
8
9
import java .util .Comparator ;
10
+ import java .util .Locale ;
9
11
import java .util .Objects ;
10
12
import java .util .function .Predicate ;
11
13
import java .util .stream .Stream ;
@@ -83,6 +85,18 @@ static UnixStream<String> date() {
83
85
return new UnixStreamImpl <>(Stream .of (LocalDate .now ().toString ()));
84
86
}
85
87
88
+ /**
89
+ * Create a new UnixStream with the current week.
90
+ *
91
+ * @return a new UnixStream with the current week.
92
+ */
93
+ static UnixStream <String > week () {
94
+ LocalDate now = LocalDate .now ();
95
+ WeekFields weekFields = WeekFields .of (Locale .getDefault ());
96
+ int weekNumber = now .get (weekFields .weekOfWeekBasedYear ());
97
+ return new UnixStreamImpl <>(Stream .of (String .valueOf (weekNumber )));
98
+ }
99
+
86
100
/**
87
101
* Create a new UnixStream with the given input.
88
102
*
Original file line number Diff line number Diff line change
1
+ package io .github .benas .unixstream .components ;
2
+
3
+ import io .github .benas .unixstream .UnixStream ;
4
+ import org .junit .Test ;
5
+
6
+ import java .io .IOException ;
7
+ import java .util .List ;
8
+ import java .util .stream .Collectors ;
9
+
10
+ import static org .assertj .core .api .Assertions .assertThat ;
11
+
12
+ public class WeekTest {
13
+
14
+ @ Test
15
+ public void week () throws IOException {
16
+ UnixStream <String > stream = UnixStream .week ();
17
+
18
+ List <String > strings = stream .collect (Collectors .toList ());
19
+ assertThat (strings ).hasSize (1 );
20
+ int week = Integer .parseInt (strings .get (0 ));
21
+
22
+ assertThat (week ).isBetween (1 , 52 );
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments