1+ /*
2+ * Copyright (c) 2025 Olivier Patry
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining
5+ * a copy of this software and associated documentation files (the "Software"),
6+ * to deal in the Software without restriction, including without limitation
7+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+ * and/or sell copies of the Software, and to permit persons to whom the Software
9+ * is furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+ */
22+
23+ package net.opatry.tasks.data
24+
25+ import androidx.room.TypeConverter
26+ import kotlinx.datetime.Instant
27+ import net.opatry.tasks.data.entity.TaskListEntity
28+
29+
30+ object CoreConverters {
31+ @TypeConverter
32+ fun instantFromString (value : String? ): Instant ? = value?.let (Instant ::parse)
33+
34+ @TypeConverter
35+ fun instantToString (instant : Instant ? ): String? = instant?.toString()
36+
37+ @TypeConverter
38+ fun sortingFromString (value : String? ): TaskListEntity .Sorting ? = value?.let (TaskListEntity .Sorting ::valueOf)
39+
40+ @TypeConverter
41+ fun sortingToString (sorting : TaskListEntity .Sorting ? ): String? = sorting?.name
42+ }
0 commit comments