TimeZoneFormatter.mjs (22569B)
1 // generated by diplomat-tool 2 import { DataProvider } from "./DataProvider.mjs" 3 import { DateTimeFormatterLoadError } from "./DateTimeFormatterLoadError.mjs" 4 import { DateTimeWriteError } from "./DateTimeWriteError.mjs" 5 import { Locale } from "./Locale.mjs" 6 import { TimeZoneInfo } from "./TimeZoneInfo.mjs" 7 import wasm from "./diplomat-wasm.mjs"; 8 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 9 10 11 /** 12 * See the [Rust documentation for `NoCalendarFormatter`](https://docs.rs/icu/latest/icu/datetime/type.NoCalendarFormatter.html) for more information. 13 */ 14 const TimeZoneFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { 15 wasm.icu4x_TimeZoneFormatter_destroy_mv1(ptr); 16 }); 17 18 export class TimeZoneFormatter { 19 // Internal ptr reference: 20 #ptr = null; 21 22 // Lifetimes are only to keep dependencies alive. 23 // Since JS won't garbage collect until there are no incoming edges. 24 #selfEdge = []; 25 26 #internalConstructor(symbol, ptr, selfEdge) { 27 if (symbol !== diplomatRuntime.internalConstructor) { 28 console.error("TimeZoneFormatter is an Opaque type. You cannot call its constructor."); 29 return; 30 } 31 this.#ptr = ptr; 32 this.#selfEdge = selfEdge; 33 34 // Are we being borrowed? If not, we can register. 35 if (this.#selfEdge.length === 0) { 36 TimeZoneFormatter_box_destroy_registry.register(this, this.#ptr); 37 } 38 39 return this; 40 } 41 get ffiValue() { 42 return this.#ptr; 43 } 44 45 46 /** 47 * Creates a zoned formatter based on a non-zoned formatter. 48 * 49 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 50 * or else unexpected behavior may occur! 51 * 52 * See the [Rust documentation for `SpecificLong`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.SpecificLong.html) for more information. 53 */ 54 static createSpecificLong(locale) { 55 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 56 57 58 const result = wasm.icu4x_TimeZoneFormatter_create_specific_long_mv1(diplomatReceive.buffer, locale.ffiValue); 59 60 try { 61 if (!diplomatReceive.resultFlag) { 62 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 63 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 64 } 65 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 66 } 67 68 finally { 69 diplomatReceive.free(); 70 } 71 } 72 73 /** 74 * Creates a zoned formatter based on a non-zoned formatter. 75 * 76 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 77 * or else unexpected behavior may occur! 78 * 79 * See the [Rust documentation for `SpecificLong`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.SpecificLong.html) for more information. 80 */ 81 static createSpecificLongWithProvider(provider, locale) { 82 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 83 84 85 const result = wasm.icu4x_TimeZoneFormatter_create_specific_long_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); 86 87 try { 88 if (!diplomatReceive.resultFlag) { 89 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 90 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 91 } 92 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 93 } 94 95 finally { 96 diplomatReceive.free(); 97 } 98 } 99 100 /** 101 * Creates a zoned formatter based on a non-zoned formatter. 102 * 103 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 104 * or else unexpected behavior may occur! 105 * 106 * See the [Rust documentation for `SpecificShort`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.SpecificShort.html) for more information. 107 */ 108 static createSpecificShort(locale) { 109 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 110 111 112 const result = wasm.icu4x_TimeZoneFormatter_create_specific_short_mv1(diplomatReceive.buffer, locale.ffiValue); 113 114 try { 115 if (!diplomatReceive.resultFlag) { 116 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 117 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 118 } 119 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 120 } 121 122 finally { 123 diplomatReceive.free(); 124 } 125 } 126 127 /** 128 * Creates a zoned formatter based on a non-zoned formatter. 129 * 130 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 131 * or else unexpected behavior may occur! 132 * 133 * See the [Rust documentation for `SpecificShort`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.SpecificShort.html) for more information. 134 */ 135 static createSpecificShortWithProvider(provider, locale) { 136 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 137 138 139 const result = wasm.icu4x_TimeZoneFormatter_create_specific_short_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); 140 141 try { 142 if (!diplomatReceive.resultFlag) { 143 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 144 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 145 } 146 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 147 } 148 149 finally { 150 diplomatReceive.free(); 151 } 152 } 153 154 /** 155 * Creates a zoned formatter based on a non-zoned formatter. 156 * 157 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 158 * or else unexpected behavior may occur! 159 * 160 * See the [Rust documentation for `LocalizedOffsetLong`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.LocalizedOffsetLong.html) for more information. 161 */ 162 static createLocalizedOffsetLong(locale) { 163 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 164 165 166 const result = wasm.icu4x_TimeZoneFormatter_create_localized_offset_long_mv1(diplomatReceive.buffer, locale.ffiValue); 167 168 try { 169 if (!diplomatReceive.resultFlag) { 170 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 171 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 172 } 173 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 174 } 175 176 finally { 177 diplomatReceive.free(); 178 } 179 } 180 181 /** 182 * Creates a zoned formatter based on a non-zoned formatter. 183 * 184 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 185 * or else unexpected behavior may occur! 186 * 187 * See the [Rust documentation for `LocalizedOffsetLong`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.LocalizedOffsetLong.html) for more information. 188 */ 189 static createLocalizedOffsetLongWithProvider(provider, locale) { 190 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 191 192 193 const result = wasm.icu4x_TimeZoneFormatter_create_localized_offset_long_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); 194 195 try { 196 if (!diplomatReceive.resultFlag) { 197 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 198 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 199 } 200 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 201 } 202 203 finally { 204 diplomatReceive.free(); 205 } 206 } 207 208 /** 209 * Creates a zoned formatter based on a non-zoned formatter. 210 * 211 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 212 * or else unexpected behavior may occur! 213 * 214 * See the [Rust documentation for `LocalizedOffsetShort`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.LocalizedOffsetShort.html) for more information. 215 */ 216 static createLocalizedOffsetShort(locale) { 217 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 218 219 220 const result = wasm.icu4x_TimeZoneFormatter_create_localized_offset_short_mv1(diplomatReceive.buffer, locale.ffiValue); 221 222 try { 223 if (!diplomatReceive.resultFlag) { 224 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 225 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 226 } 227 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 228 } 229 230 finally { 231 diplomatReceive.free(); 232 } 233 } 234 235 /** 236 * Creates a zoned formatter based on a non-zoned formatter. 237 * 238 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 239 * or else unexpected behavior may occur! 240 * 241 * See the [Rust documentation for `LocalizedOffsetShort`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.LocalizedOffsetShort.html) for more information. 242 */ 243 static createLocalizedOffsetShortWithProvider(provider, locale) { 244 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 245 246 247 const result = wasm.icu4x_TimeZoneFormatter_create_localized_offset_short_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); 248 249 try { 250 if (!diplomatReceive.resultFlag) { 251 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 252 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 253 } 254 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 255 } 256 257 finally { 258 diplomatReceive.free(); 259 } 260 } 261 262 /** 263 * Creates a zoned formatter based on a non-zoned formatter. 264 * 265 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 266 * or else unexpected behavior may occur! 267 * 268 * See the [Rust documentation for `GenericLong`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.GenericLong.html) for more information. 269 */ 270 static createGenericLong(locale) { 271 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 272 273 274 const result = wasm.icu4x_TimeZoneFormatter_create_generic_long_mv1(diplomatReceive.buffer, locale.ffiValue); 275 276 try { 277 if (!diplomatReceive.resultFlag) { 278 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 279 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 280 } 281 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 282 } 283 284 finally { 285 diplomatReceive.free(); 286 } 287 } 288 289 /** 290 * Creates a zoned formatter based on a non-zoned formatter. 291 * 292 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 293 * or else unexpected behavior may occur! 294 * 295 * See the [Rust documentation for `GenericLong`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.GenericLong.html) for more information. 296 */ 297 static createGenericLongWithProvider(provider, locale) { 298 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 299 300 301 const result = wasm.icu4x_TimeZoneFormatter_create_generic_long_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); 302 303 try { 304 if (!diplomatReceive.resultFlag) { 305 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 306 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 307 } 308 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 309 } 310 311 finally { 312 diplomatReceive.free(); 313 } 314 } 315 316 /** 317 * Creates a zoned formatter based on a non-zoned formatter. 318 * 319 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 320 * or else unexpected behavior may occur! 321 * 322 * See the [Rust documentation for `GenericShort`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.GenericShort.html) for more information. 323 */ 324 static createGenericShort(locale) { 325 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 326 327 328 const result = wasm.icu4x_TimeZoneFormatter_create_generic_short_mv1(diplomatReceive.buffer, locale.ffiValue); 329 330 try { 331 if (!diplomatReceive.resultFlag) { 332 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 333 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 334 } 335 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 336 } 337 338 finally { 339 diplomatReceive.free(); 340 } 341 } 342 343 /** 344 * Creates a zoned formatter based on a non-zoned formatter. 345 * 346 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 347 * or else unexpected behavior may occur! 348 * 349 * See the [Rust documentation for `GenericShort`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.GenericShort.html) for more information. 350 */ 351 static createGenericShortWithProvider(provider, locale) { 352 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 353 354 355 const result = wasm.icu4x_TimeZoneFormatter_create_generic_short_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); 356 357 try { 358 if (!diplomatReceive.resultFlag) { 359 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 360 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 361 } 362 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 363 } 364 365 finally { 366 diplomatReceive.free(); 367 } 368 } 369 370 /** 371 * Creates a zoned formatter based on a non-zoned formatter. 372 * 373 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 374 * or else unexpected behavior may occur! 375 * 376 * See the [Rust documentation for `Location`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.Location.html) for more information. 377 */ 378 static createLocation(locale) { 379 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 380 381 382 const result = wasm.icu4x_TimeZoneFormatter_create_location_mv1(diplomatReceive.buffer, locale.ffiValue); 383 384 try { 385 if (!diplomatReceive.resultFlag) { 386 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 387 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 388 } 389 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 390 } 391 392 finally { 393 diplomatReceive.free(); 394 } 395 } 396 397 /** 398 * Creates a zoned formatter based on a non-zoned formatter. 399 * 400 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 401 * or else unexpected behavior may occur! 402 * 403 * See the [Rust documentation for `Location`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.Location.html) for more information. 404 */ 405 static createLocationWithProvider(provider, locale) { 406 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 407 408 409 const result = wasm.icu4x_TimeZoneFormatter_create_location_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); 410 411 try { 412 if (!diplomatReceive.resultFlag) { 413 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 414 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 415 } 416 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 417 } 418 419 finally { 420 diplomatReceive.free(); 421 } 422 } 423 424 /** 425 * Creates a zoned formatter based on a non-zoned formatter. 426 * 427 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 428 * or else unexpected behavior may occur! 429 * 430 * See the [Rust documentation for `ExemplarCity`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.ExemplarCity.html) for more information. 431 */ 432 static createExemplarCity(locale) { 433 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 434 435 436 const result = wasm.icu4x_TimeZoneFormatter_create_exemplar_city_mv1(diplomatReceive.buffer, locale.ffiValue); 437 438 try { 439 if (!diplomatReceive.resultFlag) { 440 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 441 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 442 } 443 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 444 } 445 446 finally { 447 diplomatReceive.free(); 448 } 449 } 450 451 /** 452 * Creates a zoned formatter based on a non-zoned formatter. 453 * 454 * Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 455 * or else unexpected behavior may occur! 456 * 457 * See the [Rust documentation for `ExemplarCity`](https://docs.rs/icu/latest/icu/datetime/fieldsets/zone/struct.ExemplarCity.html) for more information. 458 */ 459 static createExemplarCityWithProvider(provider, locale) { 460 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 461 462 463 const result = wasm.icu4x_TimeZoneFormatter_create_exemplar_city_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); 464 465 try { 466 if (!diplomatReceive.resultFlag) { 467 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 468 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 469 } 470 return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 471 } 472 473 finally { 474 diplomatReceive.free(); 475 } 476 } 477 478 /** 479 * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.FixedCalendarDateTimeFormatter.html#method.format) for more information. 480 */ 481 format(zone) { 482 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 483 484 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 485 486 487 const result = wasm.icu4x_TimeZoneFormatter_format_mv1(diplomatReceive.buffer, this.ffiValue, zone.ffiValue, write.buffer); 488 489 try { 490 if (!diplomatReceive.resultFlag) { 491 const cause = new DateTimeWriteError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 492 throw new globalThis.Error('DateTimeWriteError: ' + cause.value, { cause }); 493 } 494 return write.readString8(); 495 } 496 497 finally { 498 diplomatReceive.free(); 499 write.free(); 500 } 501 } 502 503 constructor(symbol, ptr, selfEdge) { 504 return this.#internalConstructor(...arguments) 505 } 506 }