@@ -58,47 +58,51 @@ public actual class UtcOffset internal constructor(public actual val totalSecond
58
58
minutes = parseNumber(offsetString, 4 , true )
59
59
seconds = parseNumber(offsetString, 7 , true )
60
60
}
61
- else -> throw IllegalTimeZoneException (" Invalid ID for UtcOffset, invalid format: $offsetString " )
61
+ else -> throw DateTimeFormatException (" Invalid ID for UtcOffset, invalid format: $offsetString " )
62
62
}
63
63
val first: Char = offsetString[0 ]
64
64
if (first != ' +' && first != ' -' ) {
65
- throw IllegalTimeZoneException (
65
+ throw DateTimeFormatException (
66
66
" Invalid ID for UtcOffset, plus/minus not found when expected: $offsetString " )
67
67
}
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)
72
76
}
73
77
}
74
78
75
79
// org.threeten.bp.ZoneOffset#validate
76
80
private fun validate (hours : Int , minutes : Int , seconds : Int ) {
77
81
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" )
80
84
}
81
85
if (hours > 0 ) {
82
86
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" )
84
88
}
85
89
} else if (hours < 0 ) {
86
90
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" )
88
92
}
89
93
} 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" )
91
95
}
92
96
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" )
95
99
}
96
100
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" )
99
103
}
100
104
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" )
102
106
}
103
107
}
104
108
@@ -120,12 +124,12 @@ public actual class UtcOffset internal constructor(public actual val totalSecond
120
124
// org.threeten.bp.ZoneOffset#parseNumber
121
125
private fun parseNumber (offsetId : CharSequence , pos : Int , precededByColon : Boolean ): Int {
122
126
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 " )
124
128
}
125
129
val ch1 = offsetId[pos]
126
130
val ch2 = offsetId[pos + 1 ]
127
131
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 " )
129
133
}
130
134
return (ch1 - ' 0' ) * 10 + (ch2 - ' 0' )
131
135
}
0 commit comments