@@ -58,47 +58,51 @@ public actual class UtcOffset internal constructor(public actual val totalSecond
5858 minutes = parseNumber(offsetString, 4 , true )
5959 seconds = parseNumber(offsetString, 7 , true )
6060 }
61- else -> throw IllegalTimeZoneException (" Invalid ID for UtcOffset, invalid format: $offsetString " )
61+ else -> throw DateTimeFormatException (" Invalid ID for UtcOffset, invalid format: $offsetString " )
6262 }
6363 val first: Char = offsetString[0 ]
6464 if (first != ' +' && first != ' -' ) {
65- throw IllegalTimeZoneException (
65+ throw DateTimeFormatException (
6666 " Invalid ID for UtcOffset, plus/minus not found when expected: $offsetString " )
6767 }
68- return if (first == ' -' ) {
69- ofHoursMinutesSeconds(- hours, - minutes, - seconds)
70- } else {
71- ofHoursMinutesSeconds(hours, minutes, seconds)
68+ try {
69+ return if (first == ' -' ) {
70+ ofHoursMinutesSeconds(- hours, - minutes, - seconds)
71+ } else {
72+ ofHoursMinutesSeconds(hours, minutes, seconds)
73+ }
74+ } catch (e: IllegalArgumentException ) {
75+ throw DateTimeFormatException (e)
7276 }
7377 }
7478
7579 // org.threeten.bp.ZoneOffset#validate
7680 private fun validate (hours : Int , minutes : Int , seconds : Int ) {
7781 if (hours < - 18 || hours > 18 ) {
78- throw IllegalTimeZoneException (" Zone offset hours not in valid range: value " + hours +
79- " is not in the range -18 to 18" )
82+ throw IllegalArgumentException (" Zone offset hours not in valid range: value " + hours +
83+ " is not in the range -18 to 18" )
8084 }
8185 if (hours > 0 ) {
8286 if (minutes < 0 || seconds < 0 ) {
83- throw IllegalTimeZoneException (" Zone offset minutes and seconds must be positive because hours is positive" )
87+ throw IllegalArgumentException (" Zone offset minutes and seconds must be positive because hours is positive" )
8488 }
8589 } else if (hours < 0 ) {
8690 if (minutes > 0 || seconds > 0 ) {
87- throw IllegalTimeZoneException (" Zone offset minutes and seconds must be negative because hours is negative" )
91+ throw IllegalArgumentException (" Zone offset minutes and seconds must be negative because hours is negative" )
8892 }
8993 } else if (minutes > 0 && seconds < 0 || minutes < 0 && seconds > 0 ) {
90- throw IllegalTimeZoneException (" Zone offset minutes and seconds must have the same sign" )
94+ throw IllegalArgumentException (" Zone offset minutes and seconds must have the same sign" )
9195 }
9296 if (abs(minutes) > 59 ) {
93- throw IllegalTimeZoneException (" Zone offset minutes not in valid range: abs(value) " +
94- abs(minutes) + " is not in the range 0 to 59" )
97+ throw IllegalArgumentException (" Zone offset minutes not in valid range: abs(value) " +
98+ abs(minutes) + " is not in the range 0 to 59" )
9599 }
96100 if (abs(seconds) > 59 ) {
97- throw IllegalTimeZoneException (" Zone offset seconds not in valid range: abs(value) " +
98- abs(seconds) + " is not in the range 0 to 59" )
101+ throw IllegalArgumentException (" Zone offset seconds not in valid range: abs(value) " +
102+ abs(seconds) + " is not in the range 0 to 59" )
99103 }
100104 if (abs(hours) == 18 && (abs(minutes) > 0 || abs(seconds) > 0 )) {
101- throw IllegalTimeZoneException ( " Zone offset not in valid range: -18:00 to +18:00" )
105+ throw IllegalArgumentException ( " Utc offset not in valid range: -18:00 to +18:00" )
102106 }
103107 }
104108
@@ -120,12 +124,12 @@ public actual class UtcOffset internal constructor(public actual val totalSecond
120124 // org.threeten.bp.ZoneOffset#parseNumber
121125 private fun parseNumber (offsetId : CharSequence , pos : Int , precededByColon : Boolean ): Int {
122126 if (precededByColon && offsetId[pos - 1 ] != ' :' ) {
123- throw IllegalTimeZoneException (" Invalid ID for ZoneOffset , colon not found when expected: $offsetId " )
127+ throw DateTimeFormatException (" Invalid ID for UtcOffset , colon not found when expected: $offsetId " )
124128 }
125129 val ch1 = offsetId[pos]
126130 val ch2 = offsetId[pos + 1 ]
127131 if (ch1 < ' 0' || ch1 > ' 9' || ch2 < ' 0' || ch2 > ' 9' ) {
128- throw IllegalTimeZoneException (" Invalid ID for ZoneOffset , non numeric characters found: $offsetId " )
132+ throw DateTimeFormatException (" Invalid ID for UtcOffset , non numeric characters found: $offsetId " )
129133 }
130134 return (ch1 - ' 0' ) * 10 + (ch2 - ' 0' )
131135 }
0 commit comments