-
Notifications
You must be signed in to change notification settings - Fork 110
Fix using optional
between numbers
#362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ import kotlinx.datetime.internal.format.parser.Copyable | |
|
||
/** | ||
* A description of how month names are formatted. | ||
* | ||
* An [IllegalArgumentException] will be thrown if some month name is empty or there are duplicate names. | ||
*/ | ||
public class MonthNames( | ||
/** | ||
|
@@ -21,6 +23,14 @@ public class MonthNames( | |
) { | ||
init { | ||
require(names.size == 12) { "Month names must contain exactly 12 elements" } | ||
names.indices.forEach { ix -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the second thought about duplicates, this way users would not be able to use single-letter month names for formatting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After an internal discussion, we decided that it's not an issue with the typical use cases for single-letter month names: they are mostly used independently from the other formatting, so you probably won't see things like |
||
require(names[ix].isNotEmpty()) { "A month name can not be empty" } | ||
for (ix2 in 0 until ix) { | ||
require(names[ix] != names[ix2]) { | ||
"Month names must be unique, but '${names[ix]}' was repeated" | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -63,6 +73,8 @@ internal fun MonthNames.toKotlinCode(): String = when (this.names) { | |
|
||
/** | ||
* A description of how day of week names are formatted. | ||
* | ||
* An [IllegalArgumentException] will be thrown if some day-of-week name is empty or there are duplicate names. | ||
*/ | ||
public class DayOfWeekNames( | ||
/** | ||
|
@@ -72,6 +84,14 @@ public class DayOfWeekNames( | |
) { | ||
init { | ||
require(names.size == 7) { "Day of week names must contain exactly 7 elements" } | ||
names.indices.forEach { ix -> | ||
require(names[ix].isNotEmpty()) { "A day-of-week name can not be empty" } | ||
for (ix2 in 0 until ix) { | ||
require(names[ix] != names[ix2]) { | ||
"Day-of-week names must be unique, but '${names[ix]}' was repeated" | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we check this requirement in the
amPmMarker
call, or it fails the operation (the parsing I suppose) later?Do we need the requirement to have distinct strings here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
amPmMarker
call checks this requirement. Documented this and added the tests.Also, added the requirement for distinct strings for month days, days of the week, and AM/PM.