@@ -55,6 +55,12 @@ public class MonthNames(
55
55
}
56
56
}
57
57
58
+ internal fun MonthNames.toKotlinCode (): String = when (this .names) {
59
+ MonthNames .ENGLISH_FULL .names -> " MonthNames.${DayOfWeekNames .Companion ::ENGLISH_FULL .name} "
60
+ MonthNames .ENGLISH_ABBREVIATED .names -> " MonthNames.${DayOfWeekNames .Companion ::ENGLISH_ABBREVIATED .name} "
61
+ else -> names.joinToString(" , " , " MonthNames(" , " )" , transform = String ::toKotlinCode)
62
+ }
63
+
58
64
/* *
59
65
* A description of how day of week names are formatted.
60
66
*/
@@ -103,6 +109,12 @@ public class DayOfWeekNames(
103
109
}
104
110
}
105
111
112
+ internal fun DayOfWeekNames.toKotlinCode (): String = when (this .names) {
113
+ DayOfWeekNames .ENGLISH_FULL .names -> " DayOfWeekNames.${DayOfWeekNames .Companion ::ENGLISH_FULL .name} "
114
+ DayOfWeekNames .ENGLISH_ABBREVIATED .names -> " DayOfWeekNames.${DayOfWeekNames .Companion ::ENGLISH_ABBREVIATED .name} "
115
+ else -> names.joinToString(" , " , " DayOfWeekNames(" , " )" , transform = String ::toKotlinCode)
116
+ }
117
+
106
118
internal fun <T > getParsedField (field : T ? , name : String ): T {
107
119
if (field == null ) {
108
120
throw DateTimeFormatException (" Can not create a $name from the given input: the field $name is missing" )
@@ -170,18 +182,21 @@ internal class IncompleteLocalDate(
170
182
" ${year ? : " ??" } -${monthNumber ? : " ??" } -${dayOfMonth ? : " ??" } (day of week is ${isoDayOfWeek ? : " ??" } )"
171
183
}
172
184
173
- internal class YearDirective (padding : Padding ) :
185
+ internal class YearDirective (private val padding : Padding ) :
174
186
SignedIntFieldFormatDirective <DateFieldContainer >(
175
187
DateFields .year,
176
188
minDigits = padding.minDigits(4 ),
177
189
maxDigits = null ,
178
190
spacePadding = padding.spaces(4 ),
179
191
outputPlusOnExceededWidth = 4 ,
180
192
) {
181
- override val builderRepresentation: String = when (padding) {
193
+ override val builderRepresentation: String get() = when (padding) {
182
194
Padding .ZERO -> " ${DateTimeFormatBuilder .WithDate ::appendYear.name} ()"
183
- else -> " ${DateTimeFormatBuilder .WithDate ::appendYear.name} ($padding )"
195
+ else -> " ${DateTimeFormatBuilder .WithDate ::appendYear.name} (${ padding.toKotlinCode()} )"
184
196
}
197
+
198
+ override fun equals (other : Any? ): Boolean = other is YearDirective && padding == other.padding
199
+ override fun hashCode (): Int = padding.hashCode()
185
200
}
186
201
187
202
internal class ReducedYearDirective (val base : Int ) :
@@ -190,48 +205,63 @@ internal class ReducedYearDirective(val base: Int) :
190
205
digits = 2 ,
191
206
base = base,
192
207
) {
193
- override val builderRepresentation: String = " ${DateTimeFormatBuilder .WithDate ::appendYearTwoDigits.name} ($base )"
208
+ override val builderRepresentation: String get() = " ${DateTimeFormatBuilder .WithDate ::appendYearTwoDigits.name} ($base )"
209
+
210
+ override fun equals (other : Any? ): Boolean = other is ReducedYearDirective && base == other.base
211
+ override fun hashCode (): Int = base.hashCode()
194
212
}
195
213
196
- internal class MonthDirective (padding : Padding ) :
214
+ internal class MonthDirective (private val padding : Padding ) :
197
215
UnsignedIntFieldFormatDirective <DateFieldContainer >(
198
216
DateFields .month,
199
217
minDigits = padding.minDigits(2 ),
200
218
spacePadding = padding.spaces(2 ),
201
219
) {
202
- override val builderRepresentation: String = when (padding) {
220
+ override val builderRepresentation: String get() = when (padding) {
203
221
Padding .ZERO -> " ${DateTimeFormatBuilder .WithDate ::appendMonthNumber.name} ()"
204
- else -> " ${DateTimeFormatBuilder .WithDate ::appendMonthNumber.name} ($padding )"
222
+ else -> " ${DateTimeFormatBuilder .WithDate ::appendMonthNumber.name} (${ padding.toKotlinCode()} )"
205
223
}
224
+
225
+ override fun equals (other : Any? ): Boolean = other is MonthDirective && padding == other.padding
226
+ override fun hashCode (): Int = padding.hashCode()
206
227
}
207
228
208
- internal class MonthNameDirective (names : List <String >) :
209
- NamedUnsignedIntFieldFormatDirective <DateFieldContainer >(DateFields .month, names) {
210
- override val builderRepresentation: String =
211
- " ${DateTimeFormatBuilder .WithDate ::appendMonthName.name} (${names.toKotlinCode(String ::toKotlinCode)} )"
229
+ internal class MonthNameDirective (private val names : MonthNames ) :
230
+ NamedUnsignedIntFieldFormatDirective <DateFieldContainer >(DateFields .month, names.names) {
231
+ override val builderRepresentation: String get() =
232
+ " ${DateTimeFormatBuilder .WithDate ::appendMonthName.name} (${names.toKotlinCode()} )"
233
+
234
+ override fun equals (other : Any? ): Boolean = other is MonthNameDirective && names.names == other.names.names
235
+ override fun hashCode (): Int = names.names.hashCode()
212
236
}
213
237
214
- internal class DayDirective (padding : Padding ) :
238
+ internal class DayDirective (private val padding : Padding ) :
215
239
UnsignedIntFieldFormatDirective <DateFieldContainer >(
216
240
DateFields .dayOfMonth,
217
241
minDigits = padding.minDigits(2 ),
218
242
spacePadding = padding.spaces(2 ),
219
243
) {
220
- override val builderRepresentation: String = when (padding) {
244
+ override val builderRepresentation: String get() = when (padding) {
221
245
Padding .ZERO -> " ${DateTimeFormatBuilder .WithDate ::appendDayOfMonth.name} ()"
222
- else -> " ${DateTimeFormatBuilder .WithDate ::appendDayOfMonth.name} ($padding )"
246
+ else -> " ${DateTimeFormatBuilder .WithDate ::appendDayOfMonth.name} (${ padding.toKotlinCode()} )"
223
247
}
248
+
249
+ override fun equals (other : Any? ): Boolean = other is DayDirective && padding == other.padding
250
+ override fun hashCode (): Int = padding.hashCode()
224
251
}
225
252
226
- internal class DayOfWeekDirective (names : List < String > ) :
227
- NamedUnsignedIntFieldFormatDirective <DateFieldContainer >(DateFields .isoDayOfWeek, names) {
253
+ internal class DayOfWeekDirective (private val names : DayOfWeekNames ) :
254
+ NamedUnsignedIntFieldFormatDirective <DateFieldContainer >(DateFields .isoDayOfWeek, names.names ) {
228
255
229
- override val builderRepresentation: String =
230
- " ${DateTimeFormatBuilder .WithDate ::appendDayOfWeek.name} (${names.toKotlinCode(String ::toKotlinCode)} )"
256
+ override val builderRepresentation: String get() =
257
+ " ${DateTimeFormatBuilder .WithDate ::appendDayOfWeek.name} (${names.toKotlinCode()} )"
258
+
259
+ override fun equals (other : Any? ): Boolean = other is DayOfWeekDirective && names.names == other.names.names
260
+ override fun hashCode (): Int = names.names.hashCode()
231
261
}
232
262
233
- internal class LocalDateFormat (val actualFormat : StringFormat <DateFieldContainer >) :
234
- AbstractDateTimeFormat <LocalDate , IncompleteLocalDate >(actualFormat ) {
263
+ internal class LocalDateFormat (override val actualFormat : StringFormat <DateFieldContainer >) :
264
+ AbstractDateTimeFormat <LocalDate , IncompleteLocalDate >() {
235
265
override fun intermediateFromValue (value : LocalDate ): IncompleteLocalDate =
236
266
IncompleteLocalDate ().apply { populateFrom(value) }
237
267
@@ -259,11 +289,11 @@ internal class LocalDateFormat(val actualFormat: StringFormat<DateFieldContainer
259
289
actualBuilder.add(BasicFormatStructure (MonthDirective (padding)))
260
290
261
291
override fun appendMonthName (names : MonthNames ) =
262
- actualBuilder.add(BasicFormatStructure (MonthNameDirective (names.names )))
292
+ actualBuilder.add(BasicFormatStructure (MonthNameDirective (names)))
263
293
264
294
override fun appendDayOfMonth (padding : Padding ) = actualBuilder.add(BasicFormatStructure (DayDirective (padding)))
265
295
override fun appendDayOfWeek (names : DayOfWeekNames ) =
266
- actualBuilder.add(BasicFormatStructure (DayOfWeekDirective (names.names )))
296
+ actualBuilder.add(BasicFormatStructure (DayOfWeekDirective (names)))
267
297
268
298
@Suppress(" NO_ELSE_IN_WHEN" )
269
299
override fun appendDate (dateFormat : DateTimeFormat <LocalDate >) = when (dateFormat) {
@@ -272,8 +302,6 @@ internal class LocalDateFormat(val actualFormat: StringFormat<DateFieldContainer
272
302
273
303
override fun createEmpty (): Builder = Builder (AppendableFormatStructure ())
274
304
}
275
-
276
- override fun toString (): String = actualFormat.builderString()
277
305
}
278
306
279
307
// these are constants so that the formats are not recreated every time they are used
0 commit comments