1 /* 2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * This file is available under and governed by the GNU General Public 26 * License version 2 only, as published by the Free Software Foundation. 27 * However, the following notice accompanied the original version of this 28 * file: 29 * 30 * Copyright (c) 2010-2012, Stephen Colebourne & Michael Nascimento Santos 31 * 32 * All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions are met: 36 * 37 * * Redistributions of source code must retain the above copyright notice, 38 * this list of conditions and the following disclaimer. 39 * 40 * * Redistributions in binary form must reproduce the above copyright notice, 41 * this list of conditions and the following disclaimer in the documentation 42 * and/or other materials provided with the distribution. 43 * 44 * * Neither the name of JSR-310 nor the names of its contributors 45 * may be used to endorse or promote products derived from this software 46 * without specific prior written permission. 47 * 48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 49 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 50 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 51 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 55 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 56 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 57 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 58 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 */ 60 package tck.java.time.format; 61 62 import static org.testng.Assert.assertEquals; 63 64 import java.time.LocalDateTime; 65 import java.time.OffsetDateTime; 66 import java.time.ZoneId; 67 import java.time.ZoneOffset; 68 import java.time.ZonedDateTime; 69 import java.time.format.DateTimeFormatter; 70 import java.time.format.DateTimeFormatterBuilder; 71 import java.time.format.TextStyle; 72 import java.util.Locale; 73 74 import org.testng.annotations.BeforeMethod; 75 import org.testng.annotations.DataProvider; 76 import org.testng.annotations.Test; 77 78 /** 79 * Test DateTimeFormatterBuilder.appendOffset(). 80 */ 81 @Test 82 public class TCKOffsetPrinterParser { 83 84 private static final ZoneOffset OFFSET_UTC = ZoneOffset.UTC; 85 private static final ZoneOffset OFFSET_P0100 = ZoneOffset.ofHours(1); 86 private static final ZoneOffset OFFSET_P0123 = ZoneOffset.ofHoursMinutes(1, 23); 87 private static final ZoneOffset OFFSET_P0023 = ZoneOffset.ofHoursMinutes(0, 23); 88 private static final ZoneOffset OFFSET_P012345 = ZoneOffset.ofHoursMinutesSeconds(1, 23, 45); 89 private static final ZoneOffset OFFSET_P000045 = ZoneOffset.ofHoursMinutesSeconds(0, 0, 45); 90 private static final ZoneOffset OFFSET_M0100 = ZoneOffset.ofHours(-1); 91 private static final ZoneOffset OFFSET_M0123 = ZoneOffset.ofHoursMinutes(-1, -23); 92 private static final ZoneOffset OFFSET_M0023 = ZoneOffset.ofHoursMinutes(0, -23); 93 private static final ZoneOffset OFFSET_M012345 = ZoneOffset.ofHoursMinutesSeconds(-1, -23, -45); 94 private static final ZoneOffset OFFSET_M000045 = ZoneOffset.ofHoursMinutesSeconds(0, 0, -45); 95 private static final LocalDateTime DT_2012_06_30_12_30_40 = LocalDateTime.of(2012, 6, 30, 12, 30, 40); 96 97 private static final ZoneOffset OFFSET_P1100 = ZoneOffset.ofHours(11); 98 private static final ZoneOffset OFFSET_P1123 = ZoneOffset.ofHoursMinutes(11, 23); 99 private static final ZoneOffset OFFSET_P1023 = ZoneOffset.ofHoursMinutes(10, 23); 100 private static final ZoneOffset OFFSET_P112345 = ZoneOffset.ofHoursMinutesSeconds(11, 23, 45); 101 private static final ZoneOffset OFFSET_P100045 = ZoneOffset.ofHoursMinutesSeconds(10, 0, 45); 102 private static final ZoneOffset OFFSET_M1100 = ZoneOffset.ofHours(-11); 103 private static final ZoneOffset OFFSET_M1123 = ZoneOffset.ofHoursMinutes(-11, -23); 104 private static final ZoneOffset OFFSET_M112345 = ZoneOffset.ofHoursMinutesSeconds(-11, -23, -45); 105 private DateTimeFormatterBuilder builder; 106 107 @BeforeMethod setUp()108 public void setUp() { 109 builder = new DateTimeFormatterBuilder(); 110 } 111 112 //----------------------------------------------------------------------- 113 @DataProvider(name="print") data_print()114 Object[][] data_print() { 115 return new Object[][] { 116 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 117 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+01"}, 118 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+01"}, 119 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "Z"}, 120 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+01"}, 121 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "Z"}, 122 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-01"}, 123 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-01"}, 124 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "Z"}, 125 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-01"}, 126 {"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "Z"}, 127 128 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 129 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+01"}, 130 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+0123"}, 131 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+0023"}, 132 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+0123"}, 133 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "Z"}, 134 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-01"}, 135 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-0123"}, 136 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-0023"}, 137 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-0123"}, 138 {"+HHmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "Z"}, 139 140 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 141 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+0100"}, 142 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+0123"}, 143 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+0023"}, 144 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+0123"}, 145 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "Z"}, 146 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-0100"}, 147 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-0123"}, 148 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-0023"}, 149 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-0123"}, 150 {"+HHMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "Z"}, 151 152 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 153 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+01:00"}, 154 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+01:23"}, 155 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+00:23"}, 156 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+01:23"}, 157 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "Z"}, 158 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-01:00"}, 159 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-01:23"}, 160 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-00:23"}, 161 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-01:23"}, 162 {"+HH:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "Z"}, 163 164 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 165 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+0100"}, 166 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+0123"}, 167 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+0023"}, 168 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+012345"}, 169 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "+000045"}, 170 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-0100"}, 171 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-0123"}, 172 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-0023"}, 173 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-012345"}, 174 {"+HHMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-000045"}, 175 176 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 177 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+01:00"}, 178 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+01:23"}, 179 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+00:23"}, 180 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+01:23:45"}, 181 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00:00:45"}, 182 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-01:00"}, 183 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-01:23"}, 184 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-00:23"}, 185 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-01:23:45"}, 186 {"+HH:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00:00:45"}, 187 188 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 189 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+010000"}, 190 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+012300"}, 191 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+002300"}, 192 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+012345"}, 193 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-000045"}, 194 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-010000"}, 195 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-012300"}, 196 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-002300"}, 197 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-012345"}, 198 {"+HHMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-000045"}, 199 200 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 201 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+01:00:00"}, 202 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+01:23:00"}, 203 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+00:23:00"}, 204 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+01:23:45"}, 205 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00:00:45"}, 206 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-01:00:00"}, 207 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-01:23:00"}, 208 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-00:23:00"}, 209 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-01:23:45"}, 210 {"+HH:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00:00:45"}, 211 212 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 213 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+01"}, 214 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+01:23"}, 215 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+00:23"}, 216 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+01:23:45"}, 217 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00:00:45"}, 218 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-01"}, 219 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-01:23"}, 220 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-00:23"}, 221 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-01:23:45"}, 222 {"+HH:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00:00:45"}, 223 224 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 225 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+01"}, 226 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+0123"}, 227 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+0023"}, 228 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+012345"}, 229 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "+000045"}, 230 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-01"}, 231 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-0123"}, 232 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-0023"}, 233 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-012345"}, 234 {"+HHmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-000045"}, 235 236 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 237 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+1"}, 238 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+1"}, 239 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "Z"}, 240 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+1"}, 241 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "Z"}, 242 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-1"}, 243 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-1"}, 244 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "Z"}, 245 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-1"}, 246 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "Z"}, 247 248 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 249 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+1"}, 250 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+123"}, 251 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+023"}, 252 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+123"}, 253 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "Z"}, 254 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-1"}, 255 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-123"}, 256 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-023"}, 257 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-123"}, 258 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "Z"}, 259 260 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 261 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+100"}, 262 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+123"}, 263 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+023"}, 264 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+123"}, 265 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "Z"}, 266 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-100"}, 267 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-123"}, 268 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-023"}, 269 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-123"}, 270 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "Z"}, 271 272 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 273 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+1:00"}, 274 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+1:23"}, 275 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+0:23"}, 276 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+1:23"}, 277 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "Z"}, 278 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-1:00"}, 279 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-1:23"}, 280 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-0:23"}, 281 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-1:23"}, 282 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "Z"}, 283 284 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 285 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+100"}, 286 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+123"}, 287 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+023"}, 288 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+12345"}, 289 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "+00045"}, 290 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-100"}, 291 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-123"}, 292 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-023"}, 293 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-12345"}, 294 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00045"}, 295 296 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 297 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+1:00"}, 298 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+1:23"}, 299 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+0:23"}, 300 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+1:23:45"}, 301 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-0:00:45"}, 302 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-1:00"}, 303 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-1:23"}, 304 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-0:23"}, 305 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-1:23:45"}, 306 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-0:00:45"}, 307 308 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 309 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+10000"}, 310 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+12300"}, 311 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+02300"}, 312 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+12345"}, 313 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00045"}, 314 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-10000"}, 315 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-12300"}, 316 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-02300"}, 317 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-12345"}, 318 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00045"}, 319 320 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 321 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+1:00:00"}, 322 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+1:23:00"}, 323 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+0:23:00"}, 324 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+1:23:45"}, 325 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-0:00:45"}, 326 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-1:00:00"}, 327 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-1:23:00"}, 328 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-0:23:00"}, 329 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-1:23:45"}, 330 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-0:00:45"}, 331 332 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 333 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+1"}, 334 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+1:23"}, 335 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+0:23"}, 336 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+1:23:45"}, 337 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-0:00:45"}, 338 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-1"}, 339 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-1:23"}, 340 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-0:23"}, 341 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-1:23:45"}, 342 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-0:00:45"}, 343 344 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"}, 345 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0100, "+1"}, 346 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0123, "+123"}, 347 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P0023, "+023"}, 348 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P012345, "+12345"}, 349 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P000045, "+00045"}, 350 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0100, "-1"}, 351 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0123, "-123"}, 352 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M0023, "-023"}, 353 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M012345, "-12345"}, 354 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M000045, "-00045"}, 355 356 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+11"}, 357 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+11"}, 358 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+10"}, 359 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+11"}, 360 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_P100045, "+10"}, 361 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-11"}, 362 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-11"}, 363 {"+H", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-11"}, 364 365 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+11"}, 366 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+1123"}, 367 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+1023"}, 368 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+1123"}, 369 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_P100045, "+10"}, 370 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-11"}, 371 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-1123"}, 372 {"+Hmm", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-1123"}, 373 374 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+1100"}, 375 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+1123"}, 376 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+1023"}, 377 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+1123"}, 378 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_P100045, "+1000"}, 379 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-1100"}, 380 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-1123"}, 381 {"+HMM", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-1123"}, 382 383 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+11:00"}, 384 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+11:23"}, 385 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+10:23"}, 386 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+11:23"}, 387 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_P100045, "+10:00"}, 388 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-11:00"}, 389 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-11:23"}, 390 {"+H:MM", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-11:23"}, 391 392 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+1100"}, 393 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+1123"}, 394 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+1023"}, 395 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+112345"}, 396 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_P100045, "+100045"}, 397 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-1100"}, 398 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-1123"}, 399 {"+HMMss", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-112345"}, 400 401 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+11:00"}, 402 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+11:23"}, 403 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+10:23"}, 404 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+11:23:45"}, 405 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-11:00"}, 406 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-11:23"}, 407 {"+H:MM:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-11:23:45"}, 408 409 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+110000"}, 410 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+112300"}, 411 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+102300"}, 412 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+112345"}, 413 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-110000"}, 414 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-112300"}, 415 {"+HMMSS", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-112345"}, 416 417 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+11:00:00"}, 418 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+11:23:00"}, 419 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+10:23:00"}, 420 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+11:23:45"}, 421 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-11:00:00"}, 422 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-11:23:00"}, 423 {"+H:MM:SS", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-11:23:45"}, 424 425 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+11"}, 426 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+11:23"}, 427 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+10:23"}, 428 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+11:23:45"}, 429 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-11"}, 430 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-11:23"}, 431 {"+H:mm:ss", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-11:23:45"}, 432 433 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1100, "+11"}, 434 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1123, "+1123"}, 435 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P1023, "+1023"}, 436 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P112345, "+112345"}, 437 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_P100045, "+100045"}, 438 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M1100, "-11"}, 439 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M1123, "-1123"}, 440 {"+Hmmss", "Z", DT_2012_06_30_12_30_40, OFFSET_M112345, "-112345"}, 441 }; 442 } 443 444 @DataProvider(name="print_localized") data_print_localized()445 Object[][] data_print_localized() { 446 return new Object[][] { 447 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_UTC, "GMT"}, 448 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_P0100, "GMT+01:00"}, 449 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_P0123, "GMT+01:23"}, 450 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_P0023, "GMT+00:23"}, 451 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_P012345, "GMT+01:23:45"}, 452 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_M000045, "GMT-00:00:45"}, 453 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_M0100, "GMT-01:00"}, 454 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_M0123, "GMT-01:23"}, 455 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_M0023, "GMT-00:23"}, 456 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_M012345, "GMT-01:23:45"}, 457 {TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_M000045, "GMT-00:00:45"}, 458 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_UTC, "GMT"}, 459 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_P0100, "GMT+1"}, 460 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_P0123, "GMT+1:23"}, 461 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_P0023, "GMT+0:23"}, 462 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_P012345, "GMT+1:23:45"}, 463 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_M000045, "GMT-0:00:45"}, 464 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_M0100, "GMT-1"}, 465 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_M0123, "GMT-1:23"}, 466 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_M0023, "GMT-0:23"}, 467 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_M012345, "GMT-1:23:45"}, 468 {TextStyle.SHORT, DT_2012_06_30_12_30_40, OFFSET_M000045, "GMT-0:00:45"}, 469 }; 470 } 471 472 @Test(dataProvider="print") test_print(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected)473 public void test_print(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) { 474 ZonedDateTime zdt = ldt.atZone(zone); 475 builder.appendOffset(offsetPattern, noOffset); 476 String output = builder.toFormatter().format(zdt); 477 assertEquals(output, expected); 478 } 479 480 //----------------------------------------------------------------------- 481 @Test(dataProvider="print") test_print_pattern_X(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected)482 public void test_print_pattern_X(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) { 483 String pattern = null; 484 if (offsetPattern.equals("+HHmm") && noOffset.equals("Z")) { 485 pattern = "X"; 486 } else if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) { 487 pattern = "XX"; 488 } else if (offsetPattern.equals("+HH:MM") && noOffset.equals("Z")) { 489 pattern = "XXX"; 490 } else if (offsetPattern.equals("+HHMMss") && noOffset.equals("Z")) { 491 pattern = "XXXX"; 492 } else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) { 493 pattern = "XXXXX"; 494 } 495 if (pattern != null) { 496 ZonedDateTime zdt = ldt.atZone(zone); 497 builder.appendPattern(pattern); 498 String output = builder.toFormatter().format(zdt); 499 assertEquals(output, expected); 500 } 501 } 502 503 @Test(dataProvider="print") test_print_pattern_x(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected)504 public void test_print_pattern_x(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) { 505 String pattern = null; 506 String zero = null; 507 if (offsetPattern.equals("+HHmm") && noOffset.equals("Z")) { 508 pattern = "x"; 509 zero = "+00"; 510 } else if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) { 511 pattern = "xx"; 512 zero = "+0000"; 513 } else if (offsetPattern.equals("+HH:MM") && noOffset.equals("Z")) { 514 pattern = "xxx"; 515 zero = "+00:00"; 516 } else if (offsetPattern.equals("+HHMMss") && noOffset.equals("Z")) { 517 pattern = "xxxx"; 518 zero = "+0000"; 519 } else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) { 520 pattern = "xxxxx"; 521 zero = "+00:00"; 522 } 523 if (pattern != null) { 524 ZonedDateTime zdt = ldt.atZone(zone); 525 builder.appendPattern(pattern); 526 String output = builder.toFormatter().format(zdt); 527 assertEquals(output, (expected.equals("Z") ? zero : expected)); 528 } 529 } 530 531 @Test(dataProvider="print") test_print_pattern_Z(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected)532 public void test_print_pattern_Z(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) { 533 String pattern = null; 534 if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) { 535 ZonedDateTime zdt = ldt.atZone(zone); 536 DateTimeFormatter f1 = new DateTimeFormatterBuilder().appendPattern("Z").toFormatter(); 537 String output1 = f1.format(zdt); 538 assertEquals(output1, (expected.equals("Z") ? "+0000" : expected)); 539 540 DateTimeFormatter f2 = new DateTimeFormatterBuilder().appendPattern("ZZ").toFormatter(); 541 String output2 = f2.format(zdt); 542 assertEquals(output2, (expected.equals("Z") ? "+0000" : expected)); 543 544 DateTimeFormatter f3 = new DateTimeFormatterBuilder().appendPattern("ZZZ").toFormatter(); 545 String output3 = f3.format(zdt); 546 assertEquals(output3, (expected.equals("Z") ? "+0000" : expected)); 547 } else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) { 548 ZonedDateTime zdt = ldt.atZone(zone); 549 DateTimeFormatter f = new DateTimeFormatterBuilder().appendPattern("ZZZZZ").toFormatter(); 550 String output = f.format(zdt); 551 assertEquals(output, expected); 552 } 553 } 554 555 @Test(dataProvider="print_localized") test_print_localized(TextStyle style, LocalDateTime ldt, ZoneOffset offset, String expected)556 public void test_print_localized(TextStyle style, LocalDateTime ldt, ZoneOffset offset, String expected) { 557 OffsetDateTime odt = OffsetDateTime.of(ldt, offset); 558 ZonedDateTime zdt = ldt.atZone(offset); 559 560 DateTimeFormatter f = new DateTimeFormatterBuilder().appendLocalizedOffset(style) 561 .toFormatter(Locale.US); 562 assertEquals(f.format(odt), expected); 563 assertEquals(f.format(zdt), expected); 564 assertEquals(f.parse(expected, ZoneOffset::from), offset); 565 566 if (style == TextStyle.FULL) { 567 f = new DateTimeFormatterBuilder().appendPattern("ZZZZ") 568 .toFormatter(Locale.US); 569 assertEquals(f.format(odt), expected); 570 assertEquals(f.format(zdt), expected); 571 assertEquals(f.parse(expected, ZoneOffset::from), offset); 572 573 f = new DateTimeFormatterBuilder().appendPattern("OOOO") 574 .toFormatter(Locale.US); 575 assertEquals(f.format(odt), expected); 576 assertEquals(f.format(zdt), expected); 577 assertEquals(f.parse(expected, ZoneOffset::from), offset); 578 } 579 580 if (style == TextStyle.SHORT) { 581 f = new DateTimeFormatterBuilder().appendPattern("O") 582 .toFormatter(Locale.US); 583 assertEquals(f.format(odt), expected); 584 assertEquals(f.format(zdt), expected); 585 assertEquals(f.parse(expected, ZoneOffset::from), offset); 586 } 587 } 588 589 //----------------------------------------------------------------------- 590 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_X6rejected()591 public void test_print_pattern_X6rejected() { 592 builder.appendPattern("XXXXXX"); 593 } 594 595 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_x6rejected()596 public void test_print_pattern_x6rejected() { 597 builder.appendPattern("xxxxxx"); 598 } 599 600 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_Z6rejected()601 public void test_print_pattern_Z6rejected() { 602 builder.appendPattern("ZZZZZZ"); 603 } 604 605 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_O2rejected()606 public void test_print_pattern_O2rejected() { 607 builder.appendPattern("OO"); 608 } 609 610 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_O3rejected()611 public void test_print_pattern_O3rejected() { 612 builder.appendPattern("OOO"); 613 } 614 615 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_O5rejected()616 public void test_print_pattern_O5rejected() { 617 builder.appendPattern("OOOOO"); 618 } 619 620 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_localzed_full_standline()621 public void test_print_pattern_localzed_full_standline() { 622 builder.appendLocalizedOffset(TextStyle.FULL_STANDALONE); 623 } 624 625 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_localzed_short_standalone()626 public void test_print_pattern_localzed_short_standalone() { 627 builder.appendLocalizedOffset(TextStyle.SHORT_STANDALONE); 628 } 629 630 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_localzed_narrow()631 public void test_print_pattern_localzed_narrow() { 632 builder.appendLocalizedOffset(TextStyle.NARROW); 633 } 634 635 @Test(expectedExceptions=IllegalArgumentException.class) test_print_pattern_localzed_narrow_standalone()636 public void test_print_pattern_localzed_narrow_standalone() { 637 builder.appendLocalizedOffset(TextStyle.NARROW_STANDALONE); 638 } 639 640 } 641