Skip to content

Commit 6149a0d

Browse files
committed
Close #502: [refined4s-doobie-ce2] Add Get and Put type-class instances for refined4s.types.time types
1 parent bec1dd1 commit 6149a0d

File tree

4 files changed

+404
-2
lines changed

4 files changed

+404
-2
lines changed

modules/refined4s-doobie-ce2/shared/src/main/scala/refined4s/modules/doobie/derivation/types/all.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package refined4s.modules.doobie.derivation.types
33
/** @author Kevin Lee
44
* @since 2023-12-27
55
*/
6-
trait all extends numeric, strings, network
6+
trait all extends numeric, strings, network, time
77
object all extends all
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package refined4s.modules.doobie.derivation.types
2+
3+
import cats.Show
4+
import doobie.{Get, Put}
5+
import refined4s.types.time.*
6+
7+
/** @author Kevin Lee
8+
* @since 2025-09-03
9+
*/
10+
trait time {
11+
12+
inline given derivedMonthGet: Get[Month] = time.derivedMonthGet
13+
inline given derivedMonthPut: Put[Month] = time.derivedMonthPut
14+
15+
inline given derivedDayGet: Get[Day] = time.derivedDayGet
16+
inline given derivedDayPut: Put[Day] = time.derivedDayPut
17+
18+
inline given derivedHourGet: Get[Hour] = time.derivedHourGet
19+
inline given derivedHourPut: Put[Hour] = time.derivedHourPut
20+
21+
inline given derivedMinuteGet: Get[Minute] = time.derivedMinuteGet
22+
inline given derivedMinutePut: Put[Minute] = time.derivedMinutePut
23+
24+
inline given derivedSecondGet: Get[Second] = time.derivedSecondGet
25+
inline given derivedSecondPut: Put[Second] = time.derivedSecondPut
26+
27+
inline given derivedMillisGet: Get[Millis] = time.derivedMillisGet
28+
inline given derivedMillisPut: Put[Millis] = time.derivedMillisPut
29+
30+
}
31+
object time {
32+
33+
given derivedMonthGet: Get[Month] = Get[Int].temap(Month.from)
34+
given derivedMonthPut: Put[Month] = Put[Int].contramap(_.value)
35+
36+
given derivedDayGet: Get[Day] = Get[Int].temap(Day.from)
37+
given derivedDayPut: Put[Day] = Put[Int].contramap(_.value)
38+
39+
given derivedHourGet: Get[Hour] = Get[Int].temap(Hour.from)
40+
given derivedHourPut: Put[Hour] = Put[Int].contramap(_.value)
41+
42+
given derivedMinuteGet: Get[Minute] = Get[Int].temap(Minute.from)
43+
given derivedMinutePut: Put[Minute] = Put[Int].contramap(_.value)
44+
45+
given derivedSecondGet: Get[Second] = Get[Int].temap(Second.from)
46+
given derivedSecondPut: Put[Second] = Put[Int].contramap(_.value)
47+
48+
given derivedMillisGet: Get[Millis] = Get[Int].temap(Millis.from)
49+
given derivedMillisPut: Put[Millis] = Put[Int].contramap(_.value)
50+
51+
}

modules/refined4s-doobie-ce2/shared/src/test/scala/refined4s/modules/doobie/derivation/types/allSpec.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ object allSpec extends Properties, RunSyncCe2, RunWithDb {
2323
override protected val networkTypeClasses: network = refined4s.modules.doobie.derivation.types.all
2424
}
2525

26+
object timeSpecWithAll extends timeSpec {
27+
override protected val timeTypeClasses: time = refined4s.modules.doobie.derivation.types.all
28+
}
29+
2630
override def tests: List[Test] =
27-
numericSpecWithAll.allTests ++ stringsSpecWithAll.allTests ++ networkSpecWithAll.allTests
31+
numericSpecWithAll.allTests ++ stringsSpecWithAll.allTests ++ networkSpecWithAll.allTests ++ timeSpecWithAll.allTests
2832

2933
}

0 commit comments

Comments
 (0)