Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/faker/providers/date_time/__init__.py: 32%

321 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1import re 

2 

3from calendar import timegm 

4from datetime import MAXYEAR 

5from datetime import date as dtdate 

6from datetime import datetime 

7from datetime import time as dttime 

8from datetime import timedelta 

9from datetime import tzinfo as TzInfo 

10from typing import Any, Callable, Dict, Iterator, Optional, Tuple, Union 

11 

12from dateutil import relativedelta 

13from dateutil.tz import gettz, tzlocal, tzutc 

14 

15from faker.typing import Country, DateParseType 

16 

17from .. import BaseProvider, ElementsType 

18 

19localized = True 

20 

21 

22def datetime_to_timestamp(dt: Union[dtdate, datetime]) -> int: 

23 if isinstance(dt, datetime) and getattr(dt, "tzinfo", None) is not None: 23 ↛ 24line 23 didn't jump to line 24, because the condition on line 23 was never true

24 dt = dt.astimezone(tzutc()) 

25 return timegm(dt.timetuple()) 

26 

27 

28def timestamp_to_datetime(timestamp: Union[int, float], tzinfo: Optional[TzInfo]) -> datetime: 

29 if tzinfo is None: 

30 pick = convert_timestamp_to_datetime(timestamp, tzlocal()) 

31 return pick.astimezone(tzutc()).replace(tzinfo=None) 

32 return convert_timestamp_to_datetime(timestamp, tzinfo) 

33 

34 

35def change_year(current_date: dtdate, year_diff: int) -> dtdate: 

36 """ 

37 Unless the current_date is February 29th, it is fine to just subtract years. 

38 If it is a leap day, and we are rolling back to a non-leap year, it will 

39 cause a ValueError. 

40 Since this is relatively uncommon, just catch the error and roll forward to 

41 March 1 

42 

43 current_date: date object 

44 year_diff: int year delta value, positive or negative 

45 """ 

46 year = current_date.year + year_diff 

47 try: 

48 return current_date.replace(year=year) 

49 except ValueError as e: 

50 # ValueError thrown if trying to move date to a non-leap year if the current 

51 # date is February 29th 

52 if year != 0 and current_date.month == 2 and current_date.day == 29: 

53 return current_date.replace(month=3, day=1, year=year) 

54 else: 

55 raise e 

56 

57 

58class ParseError(ValueError): 

59 pass 

60 

61 

62timedelta_pattern: str = r"" 

63for name, sym in [ 

64 ("years", "y"), 

65 ("months", "M"), 

66 ("weeks", "w"), 

67 ("days", "d"), 

68 ("hours", "h"), 

69 ("minutes", "m"), 

70 ("seconds", "s"), 

71]: 

72 timedelta_pattern += r"((?P<{}>(?:\+|-)\d+?){})?".format(name, sym) 

73 

74 

75class Provider(BaseProvider): 

76 centuries: ElementsType[str] = [ 

77 "I", 

78 "II", 

79 "III", 

80 "IV", 

81 "V", 

82 "VI", 

83 "VII", 

84 "VIII", 

85 "IX", 

86 "X", 

87 "XI", 

88 "XII", 

89 "XIII", 

90 "XIV", 

91 "XV", 

92 "XVI", 

93 "XVII", 

94 "XVIII", 

95 "XIX", 

96 "XX", 

97 "XXI", 

98 ] 

99 

100 countries = [ 

101 Country( 

102 timezones=["Europe/Andorra"], 

103 alpha_2_code="AD", 

104 alpha_3_code="AND", 

105 continent="Europe", 

106 name="Andorra", 

107 capital="Andorra la Vella", 

108 ), 

109 Country( 

110 timezones=["Asia/Kabul"], 

111 alpha_2_code="AF", 

112 alpha_3_code="AFG", 

113 continent="Asia", 

114 name="Afghanistan", 

115 capital="Kabul", 

116 ), 

117 Country( 

118 timezones=["America/Antigua"], 

119 alpha_2_code="AG", 

120 alpha_3_code="ATG", 

121 continent="North America", 

122 name="Antigua and Barbuda", 

123 capital="St. John's", 

124 ), 

125 Country( 

126 timezones=["Europe/Tirane"], 

127 alpha_2_code="AL", 

128 alpha_3_code="ALB", 

129 continent="Europe", 

130 name="Albania", 

131 capital="Tirana", 

132 ), 

133 Country( 

134 timezones=["Asia/Yerevan"], 

135 alpha_2_code="AM", 

136 alpha_3_code="ARM", 

137 continent="Asia", 

138 name="Armenia", 

139 capital="Yerevan", 

140 ), 

141 Country( 

142 timezones=["Africa/Luanda"], 

143 alpha_2_code="AO", 

144 alpha_3_code="AGO", 

145 continent="Africa", 

146 name="Angola", 

147 capital="Luanda", 

148 ), 

149 Country( 

150 timezones=[ 

151 "America/Argentina/Buenos_Aires", 

152 "America/Argentina/Cordoba", 

153 "America/Argentina/Jujuy", 

154 "America/Argentina/Tucuman", 

155 "America/Argentina/Catamarca", 

156 "America/Argentina/La_Rioja", 

157 "America/Argentina/San_Juan", 

158 "America/Argentina/Mendoza", 

159 "America/Argentina/Rio_Gallegos", 

160 "America/Argentina/Ushuaia", 

161 ], 

162 alpha_2_code="AR", 

163 alpha_3_code="ARG", 

164 continent="South America", 

165 name="Argentina", 

166 capital="Buenos Aires", 

167 ), 

168 Country( 

169 timezones=["Europe/Vienna"], 

170 alpha_2_code="AT", 

171 alpha_3_code="AUT", 

172 continent="Europe", 

173 name="Austria", 

174 capital="Vienna", 

175 ), 

176 Country( 

177 timezones=[ 

178 "Australia/Lord_Howe", 

179 "Australia/Hobart", 

180 "Australia/Currie", 

181 "Australia/Melbourne", 

182 "Australia/Sydney", 

183 "Australia/Broken_Hill", 

184 "Australia/Brisbane", 

185 "Australia/Lindeman", 

186 "Australia/Adelaide", 

187 "Australia/Darwin", 

188 "Australia/Perth", 

189 ], 

190 alpha_2_code="AU", 

191 alpha_3_code="AUS", 

192 continent="Oceania", 

193 name="Australia", 

194 capital="Canberra", 

195 ), 

196 Country( 

197 timezones=["Asia/Baku"], 

198 alpha_2_code="AZ", 

199 alpha_3_code="AZE", 

200 continent="Asia", 

201 name="Azerbaijan", 

202 capital="Baku", 

203 ), 

204 Country( 

205 timezones=["America/Barbados"], 

206 alpha_2_code="BB", 

207 alpha_3_code="BRB", 

208 continent="North America", 

209 name="Barbados", 

210 capital="Bridgetown", 

211 ), 

212 Country( 

213 timezones=["Asia/Dhaka"], 

214 alpha_2_code="BD", 

215 alpha_3_code="BGD", 

216 continent="Asia", 

217 name="Bangladesh", 

218 capital="Dhaka", 

219 ), 

220 Country( 

221 timezones=["Europe/Brussels"], 

222 alpha_2_code="BE", 

223 alpha_3_code="BEL", 

224 continent="Europe", 

225 name="Belgium", 

226 capital="Brussels", 

227 ), 

228 Country( 

229 timezones=["Africa/Ouagadougou"], 

230 alpha_2_code="BF", 

231 alpha_3_code="BFA", 

232 continent="Africa", 

233 name="Burkina Faso", 

234 capital="Ouagadougou", 

235 ), 

236 Country( 

237 timezones=["Europe/Sofia"], 

238 alpha_2_code="BG", 

239 alpha_3_code="BGR", 

240 continent="Europe", 

241 name="Bulgaria", 

242 capital="Sofia", 

243 ), 

244 Country( 

245 timezones=["Asia/Bahrain"], 

246 alpha_2_code="BH", 

247 alpha_3_code="BHR", 

248 continent="Asia", 

249 name="Bahrain", 

250 capital="Manama", 

251 ), 

252 Country( 

253 timezones=["Africa/Bujumbura"], 

254 alpha_2_code="BI", 

255 alpha_3_code="BDI", 

256 continent="Africa", 

257 name="Burundi", 

258 capital="Bujumbura", 

259 ), 

260 Country( 

261 timezones=["Africa/Porto-Novo"], 

262 alpha_2_code="BJ", 

263 alpha_3_code="BEN", 

264 continent="Africa", 

265 name="Benin", 

266 capital="Porto-Novo", 

267 ), 

268 Country( 

269 timezones=["Asia/Brunei"], 

270 alpha_2_code="BN", 

271 alpha_3_code="BRN", 

272 continent="Asia", 

273 name="Brunei Darussalam", 

274 capital="Bandar Seri Begawan", 

275 ), 

276 Country( 

277 timezones=["America/La_Paz"], 

278 alpha_2_code="BO", 

279 alpha_3_code="BOL", 

280 continent="South America", 

281 name="Bolivia", 

282 capital="Sucre", 

283 ), 

284 Country( 

285 timezones=[ 

286 "America/Noronha", 

287 "America/Belem", 

288 "America/Fortaleza", 

289 "America/Recife", 

290 "America/Araguaina", 

291 "America/Maceio", 

292 "America/Bahia", 

293 "America/Sao_Paulo", 

294 "America/Campo_Grande", 

295 "America/Cuiaba", 

296 "America/Porto_Velho", 

297 "America/Boa_Vista", 

298 "America/Manaus", 

299 "America/Eirunepe", 

300 "America/Rio_Branco", 

301 ], 

302 alpha_2_code="BR", 

303 alpha_3_code="BRA", 

304 continent="South America", 

305 name="Brazil", 

306 capital="Bras\xc3\xadlia", 

307 ), 

308 Country( 

309 timezones=["America/Nassau"], 

310 alpha_2_code="BS", 

311 alpha_3_code="BHS", 

312 continent="North America", 

313 name="Bahamas", 

314 capital="Nassau", 

315 ), 

316 Country( 

317 timezones=["Asia/Thimphu"], 

318 alpha_2_code="BT", 

319 alpha_3_code="BTN", 

320 continent="Asia", 

321 name="Bhutan", 

322 capital="Thimphu", 

323 ), 

324 Country( 

325 timezones=["Africa/Gaborone"], 

326 alpha_2_code="BW", 

327 alpha_3_code="BWA", 

328 continent="Africa", 

329 name="Botswana", 

330 capital="Gaborone", 

331 ), 

332 Country( 

333 timezones=["Europe/Minsk"], 

334 alpha_2_code="BY", 

335 alpha_3_code="BLR", 

336 continent="Europe", 

337 name="Belarus", 

338 capital="Minsk", 

339 ), 

340 Country( 

341 timezones=["America/Belize"], 

342 alpha_2_code="BZ", 

343 alpha_3_code="BLZ", 

344 continent="North America", 

345 name="Belize", 

346 capital="Belmopan", 

347 ), 

348 Country( 

349 timezones=[ 

350 "America/St_Johns", 

351 "America/Halifax", 

352 "America/Glace_Bay", 

353 "America/Moncton", 

354 "America/Goose_Bay", 

355 "America/Blanc-Sablon", 

356 "America/Montreal", 

357 "America/Toronto", 

358 "America/Nipigon", 

359 "America/Thunder_Bay", 

360 "America/Pangnirtung", 

361 "America/Iqaluit", 

362 "America/Atikokan", 

363 "America/Rankin_Inlet", 

364 "America/Winnipeg", 

365 "America/Rainy_River", 

366 "America/Cambridge_Bay", 

367 "America/Regina", 

368 "America/Swift_Current", 

369 "America/Edmonton", 

370 "America/Yellowknife", 

371 "America/Inuvik", 

372 "America/Dawson_Creek", 

373 "America/Vancouver", 

374 "America/Whitehorse", 

375 "America/Dawson", 

376 ], 

377 alpha_2_code="CA", 

378 alpha_3_code="CAN", 

379 continent="North America", 

380 name="Canada", 

381 capital="Ottawa", 

382 ), 

383 Country( 

384 timezones=["Africa/Kinshasa", "Africa/Lubumbashi"], 

385 alpha_2_code="CD", 

386 alpha_3_code="COD", 

387 continent="Africa", 

388 name="Democratic Republic of the Congo", 

389 capital="Kinshasa", 

390 ), 

391 Country( 

392 timezones=["Africa/Brazzaville"], 

393 alpha_2_code="CG", 

394 alpha_3_code="COG", 

395 continent="Africa", 

396 name="Republic of the Congo", 

397 capital="Brazzaville", 

398 ), 

399 Country( 

400 timezones=["Africa/Abidjan"], 

401 alpha_2_code="CI", 

402 alpha_3_code="CIV", 

403 continent="Africa", 

404 name="C\xc3\xb4te d'Ivoire", 

405 capital="Yamoussoukro", 

406 ), 

407 Country( 

408 timezones=["America/Santiago", "Pacific/Easter"], 

409 alpha_2_code="CL", 

410 alpha_3_code="CHL", 

411 continent="South America", 

412 name="Chile", 

413 capital="Santiago", 

414 ), 

415 Country( 

416 timezones=["Africa/Douala"], 

417 alpha_2_code="CM", 

418 alpha_3_code="CMR", 

419 continent="Africa", 

420 name="Cameroon", 

421 capital="Yaound\xc3\xa9", 

422 ), 

423 Country( 

424 timezones=[ 

425 "Asia/Shanghai", 

426 "Asia/Harbin", 

427 "Asia/Chongqing", 

428 "Asia/Urumqi", 

429 "Asia/Kashgar", 

430 ], 

431 alpha_2_code="CN", 

432 alpha_3_code="CHN", 

433 continent="Asia", 

434 name="People's Republic of China", 

435 capital="Beijing", 

436 ), 

437 Country( 

438 timezones=["America/Bogota"], 

439 alpha_2_code="CO", 

440 alpha_3_code="COL", 

441 continent="South America", 

442 name="Colombia", 

443 capital="Bogot\xc3\xa1", 

444 ), 

445 Country( 

446 timezones=["America/Costa_Rica"], 

447 alpha_2_code="CR", 

448 alpha_3_code="CRI", 

449 continent="North America", 

450 name="Costa Rica", 

451 capital="San Jos\xc3\xa9", 

452 ), 

453 Country( 

454 timezones=["America/Havana"], 

455 alpha_2_code="CU", 

456 alpha_3_code="CUB", 

457 continent="North America", 

458 name="Cuba", 

459 capital="Havana", 

460 ), 

461 Country( 

462 timezones=["Atlantic/Cape_Verde"], 

463 alpha_2_code="CV", 

464 alpha_3_code="CPV", 

465 continent="Africa", 

466 name="Cape Verde", 

467 capital="Praia", 

468 ), 

469 Country( 

470 timezones=["Asia/Nicosia"], 

471 alpha_2_code="CY", 

472 alpha_3_code="CYP", 

473 continent="Asia", 

474 name="Cyprus", 

475 capital="Nicosia", 

476 ), 

477 Country( 

478 timezones=["Europe/Prague"], 

479 alpha_2_code="CZ", 

480 alpha_3_code="CZE", 

481 continent="Europe", 

482 name="Czech Republic", 

483 capital="Prague", 

484 ), 

485 Country( 

486 timezones=["Europe/Berlin"], 

487 alpha_2_code="DE", 

488 alpha_3_code="DEU", 

489 continent="Europe", 

490 name="Germany", 

491 capital="Berlin", 

492 ), 

493 Country( 

494 timezones=["Africa/Djibouti"], 

495 alpha_2_code="DJ", 

496 alpha_3_code="DJI", 

497 continent="Africa", 

498 name="Djibouti", 

499 capital="Djibouti City", 

500 ), 

501 Country( 

502 timezones=["Europe/Copenhagen"], 

503 alpha_2_code="DK", 

504 alpha_3_code="DNK", 

505 continent="Europe", 

506 name="Denmark", 

507 capital="Copenhagen", 

508 ), 

509 Country( 

510 timezones=["America/Dominica"], 

511 alpha_2_code="DM", 

512 alpha_3_code="DMA", 

513 continent="North America", 

514 name="Dominica", 

515 capital="Roseau", 

516 ), 

517 Country( 

518 timezones=["America/Santo_Domingo"], 

519 alpha_2_code="DO", 

520 alpha_3_code="DOM", 

521 continent="North America", 

522 name="Dominican Republic", 

523 capital="Santo Domingo", 

524 ), 

525 Country( 

526 timezones=["America/Guayaquil", "Pacific/Galapagos"], 

527 alpha_2_code="EC", 

528 alpha_3_code="ECU", 

529 continent="South America", 

530 name="Ecuador", 

531 capital="Quito", 

532 ), 

533 Country( 

534 timezones=["Europe/Tallinn"], 

535 alpha_2_code="EE", 

536 alpha_3_code="EST", 

537 continent="Europe", 

538 name="Estonia", 

539 capital="Tallinn", 

540 ), 

541 Country( 

542 timezones=["Africa/Cairo"], 

543 alpha_2_code="EG", 

544 alpha_3_code="EGY", 

545 continent="Africa", 

546 name="Egypt", 

547 capital="Cairo", 

548 ), 

549 Country( 

550 timezones=["Africa/Asmera"], 

551 alpha_2_code="ER", 

552 alpha_3_code="ERI", 

553 continent="Africa", 

554 name="Eritrea", 

555 capital="Asmara", 

556 ), 

557 Country( 

558 timezones=["Africa/Addis_Ababa"], 

559 alpha_2_code="ET", 

560 alpha_3_code="ETH", 

561 continent="Africa", 

562 name="Ethiopia", 

563 capital="Addis Ababa", 

564 ), 

565 Country( 

566 timezones=["Europe/Helsinki"], 

567 alpha_2_code="FI", 

568 alpha_3_code="FIN", 

569 continent="Europe", 

570 name="Finland", 

571 capital="Helsinki", 

572 ), 

573 Country( 

574 timezones=["Pacific/Fiji"], 

575 alpha_2_code="FJ", 

576 alpha_3_code="FJI", 

577 continent="Oceania", 

578 name="Fiji", 

579 capital="Suva", 

580 ), 

581 Country( 

582 timezones=["Europe/Paris"], 

583 alpha_2_code="FR", 

584 alpha_3_code="FRA", 

585 continent="Europe", 

586 name="France", 

587 capital="Paris", 

588 ), 

589 Country( 

590 timezones=["Africa/Libreville"], 

591 alpha_2_code="GA", 

592 alpha_3_code="GAB", 

593 continent="Africa", 

594 name="Gabon", 

595 capital="Libreville", 

596 ), 

597 Country( 

598 timezones=["Asia/Tbilisi"], 

599 alpha_2_code="GE", 

600 alpha_3_code="GEO", 

601 continent="Asia", 

602 name="Georgia", 

603 capital="Tbilisi", 

604 ), 

605 Country( 

606 timezones=["Africa/Accra"], 

607 alpha_2_code="GH", 

608 alpha_3_code="GHA", 

609 continent="Africa", 

610 name="Ghana", 

611 capital="Accra", 

612 ), 

613 Country( 

614 timezones=["Africa/Banjul"], 

615 alpha_2_code="GM", 

616 alpha_3_code="GMB", 

617 continent="Africa", 

618 name="The Gambia", 

619 capital="Banjul", 

620 ), 

621 Country( 

622 timezones=["Africa/Conakry"], 

623 alpha_2_code="GN", 

624 alpha_3_code="GIN", 

625 continent="Africa", 

626 name="Guinea", 

627 capital="Conakry", 

628 ), 

629 Country( 

630 timezones=["Europe/Athens"], 

631 alpha_2_code="GR", 

632 alpha_3_code="GRC", 

633 continent="Europe", 

634 name="Greece", 

635 capital="Athens", 

636 ), 

637 Country( 

638 timezones=["America/Guatemala"], 

639 alpha_2_code="GT", 

640 alpha_3_code="GTM", 

641 continent="North America", 

642 name="Guatemala", 

643 capital="Guatemala City", 

644 ), 

645 Country( 

646 timezones=["America/Guatemala"], 

647 alpha_2_code="HT", 

648 alpha_3_code="HTI", 

649 continent="North America", 

650 name="Haiti", 

651 capital="Port-au-Prince", 

652 ), 

653 Country( 

654 timezones=["Africa/Bissau"], 

655 alpha_2_code="GW", 

656 alpha_3_code="GNB", 

657 continent="Africa", 

658 name="Guinea-Bissau", 

659 capital="Bissau", 

660 ), 

661 Country( 

662 timezones=["America/Guyana"], 

663 alpha_2_code="GY", 

664 alpha_3_code="GUY", 

665 continent="South America", 

666 name="Guyana", 

667 capital="Georgetown", 

668 ), 

669 Country( 

670 timezones=["America/Tegucigalpa"], 

671 alpha_2_code="HN", 

672 alpha_3_code="HND", 

673 continent="North America", 

674 name="Honduras", 

675 capital="Tegucigalpa", 

676 ), 

677 Country( 

678 timezones=["Europe/Budapest"], 

679 alpha_2_code="HU", 

680 alpha_3_code="HUN", 

681 continent="Europe", 

682 name="Hungary", 

683 capital="Budapest", 

684 ), 

685 Country( 

686 timezones=[ 

687 "Asia/Jakarta", 

688 "Asia/Pontianak", 

689 "Asia/Makassar", 

690 "Asia/Jayapura", 

691 ], 

692 alpha_2_code="ID", 

693 alpha_3_code="IDN", 

694 continent="Asia", 

695 name="Indonesia", 

696 capital="Jakarta", 

697 ), 

698 Country( 

699 timezones=["Europe/Dublin"], 

700 alpha_2_code="IE", 

701 alpha_3_code="IRL", 

702 continent="Europe", 

703 name="Republic of Ireland", 

704 capital="Dublin", 

705 ), 

706 Country( 

707 timezones=["Asia/Jerusalem"], 

708 alpha_2_code="IL", 

709 alpha_3_code="ISR", 

710 continent="Asia", 

711 name="Israel", 

712 capital="Jerusalem", 

713 ), 

714 Country( 

715 timezones=["Asia/Calcutta"], 

716 alpha_2_code="IN", 

717 alpha_3_code="IND", 

718 continent="Asia", 

719 name="India", 

720 capital="New Delhi", 

721 ), 

722 Country( 

723 timezones=["Asia/Baghdad"], 

724 alpha_2_code="IQ", 

725 alpha_3_code="IRQ", 

726 continent="Asia", 

727 name="Iraq", 

728 capital="Baghdad", 

729 ), 

730 Country( 

731 timezones=["Asia/Tehran"], 

732 alpha_2_code="IR", 

733 alpha_3_code="IRN", 

734 continent="Asia", 

735 name="Iran", 

736 capital="Tehran", 

737 ), 

738 Country( 

739 timezones=["Atlantic/Reykjavik"], 

740 alpha_2_code="IS", 

741 alpha_3_code="ISL", 

742 continent="Europe", 

743 name="Iceland", 

744 capital="Reykjav\xc3\xadk", 

745 ), 

746 Country( 

747 timezones=["Europe/Rome"], 

748 alpha_2_code="IT", 

749 alpha_3_code="ITA", 

750 continent="Europe", 

751 name="Italy", 

752 capital="Rome", 

753 ), 

754 Country( 

755 timezones=["America/Jamaica"], 

756 alpha_2_code="JM", 

757 alpha_3_code="JAM", 

758 continent="North America", 

759 name="Jamaica", 

760 capital="Kingston", 

761 ), 

762 Country( 

763 timezones=["Asia/Amman"], 

764 alpha_2_code="JO", 

765 alpha_3_code="JOR", 

766 continent="Asia", 

767 name="Jordan", 

768 capital="Amman", 

769 ), 

770 Country( 

771 timezones=["Asia/Tokyo"], 

772 alpha_2_code="JP", 

773 alpha_3_code="JPN", 

774 continent="Asia", 

775 name="Japan", 

776 capital="Tokyo", 

777 ), 

778 Country( 

779 timezones=["Africa/Nairobi"], 

780 alpha_2_code="KE", 

781 alpha_3_code="KEN", 

782 continent="Africa", 

783 name="Kenya", 

784 capital="Nairobi", 

785 ), 

786 Country( 

787 timezones=["Asia/Bishkek"], 

788 alpha_2_code="KG", 

789 alpha_3_code="KGZ", 

790 continent="Asia", 

791 name="Kyrgyzstan", 

792 capital="Bishkek", 

793 ), 

794 Country( 

795 timezones=["Pacific/Tarawa", "Pacific/Enderbury", "Pacific/Kiritimati"], 

796 alpha_2_code="KI", 

797 alpha_3_code="KIR", 

798 continent="Oceania", 

799 name="Kiribati", 

800 capital="Tarawa", 

801 ), 

802 Country( 

803 timezones=["Asia/Pyongyang"], 

804 alpha_2_code="KP", 

805 alpha_3_code="PRK", 

806 continent="Asia", 

807 name="North Korea", 

808 capital="Pyongyang", 

809 ), 

810 Country( 

811 timezones=["Asia/Seoul"], 

812 alpha_2_code="KR", 

813 alpha_3_code="KOR", 

814 continent="Asia", 

815 name="South Korea", 

816 capital="Seoul", 

817 ), 

818 Country( 

819 timezones=["Asia/Kuwait"], 

820 alpha_2_code="KW", 

821 alpha_3_code="KWT", 

822 continent="Asia", 

823 name="Kuwait", 

824 capital="Kuwait City", 

825 ), 

826 Country( 

827 timezones=["Asia/Beirut"], 

828 alpha_2_code="LB", 

829 alpha_3_code="LBN", 

830 continent="Asia", 

831 name="Lebanon", 

832 capital="Beirut", 

833 ), 

834 Country( 

835 timezones=["Europe/Vaduz"], 

836 alpha_2_code="LI", 

837 alpha_3_code="LIE", 

838 continent="Europe", 

839 name="Liechtenstein", 

840 capital="Vaduz", 

841 ), 

842 Country( 

843 timezones=["Africa/Monrovia"], 

844 alpha_2_code="LR", 

845 alpha_3_code="LBR", 

846 continent="Africa", 

847 name="Liberia", 

848 capital="Monrovia", 

849 ), 

850 Country( 

851 timezones=["Africa/Maseru"], 

852 alpha_2_code="LS", 

853 alpha_3_code="LSO", 

854 continent="Africa", 

855 name="Lesotho", 

856 capital="Maseru", 

857 ), 

858 Country( 

859 timezones=["Europe/Vilnius"], 

860 alpha_2_code="LT", 

861 alpha_3_code="LTU", 

862 continent="Europe", 

863 name="Lithuania", 

864 capital="Vilnius", 

865 ), 

866 Country( 

867 timezones=["Europe/Luxembourg"], 

868 alpha_2_code="LU", 

869 alpha_3_code="LUX", 

870 continent="Europe", 

871 name="Luxembourg", 

872 capital="Luxembourg City", 

873 ), 

874 Country( 

875 timezones=["Europe/Riga"], 

876 alpha_2_code="LV", 

877 alpha_3_code="LVA", 

878 continent="Europe", 

879 name="Latvia", 

880 capital="Riga", 

881 ), 

882 Country( 

883 timezones=["Africa/Tripoli"], 

884 alpha_2_code="LY", 

885 alpha_3_code="LBY", 

886 continent="Africa", 

887 name="Libya", 

888 capital="Tripoli", 

889 ), 

890 Country( 

891 timezones=["Indian/Antananarivo"], 

892 alpha_2_code="MG", 

893 alpha_3_code="MDG", 

894 continent="Africa", 

895 name="Madagascar", 

896 capital="Antananarivo", 

897 ), 

898 Country( 

899 timezones=["Pacific/Majuro", "Pacific/Kwajalein"], 

900 alpha_2_code="MH", 

901 alpha_3_code="MHL", 

902 continent="Oceania", 

903 name="Marshall Islands", 

904 capital="Majuro", 

905 ), 

906 Country( 

907 timezones=["Europe/Skopje"], 

908 alpha_2_code="MK", 

909 alpha_3_code="MKD", 

910 continent="Europe", 

911 name="Macedonia", 

912 capital="Skopje", 

913 ), 

914 Country( 

915 timezones=["Africa/Bamako"], 

916 alpha_2_code="ML", 

917 alpha_3_code="MLI", 

918 continent="Africa", 

919 name="Mali", 

920 capital="Bamako", 

921 ), 

922 Country( 

923 timezones=["Asia/Rangoon"], 

924 alpha_2_code="MM", 

925 alpha_3_code="MMR", 

926 continent="Asia", 

927 name="Myanmar", 

928 capital="Naypyidaw", 

929 ), 

930 Country( 

931 timezones=["Asia/Ulaanbaatar", "Asia/Hovd", "Asia/Choibalsan"], 

932 alpha_2_code="MN", 

933 alpha_3_code="MNG", 

934 continent="Asia", 

935 name="Mongolia", 

936 capital="Ulaanbaatar", 

937 ), 

938 Country( 

939 timezones=["Africa/Nouakchott"], 

940 alpha_2_code="MR", 

941 alpha_3_code="MRT", 

942 continent="Africa", 

943 name="Mauritania", 

944 capital="Nouakchott", 

945 ), 

946 Country( 

947 timezones=["Europe/Malta"], 

948 alpha_2_code="MT", 

949 alpha_3_code="MLT", 

950 continent="Europe", 

951 name="Malta", 

952 capital="Valletta", 

953 ), 

954 Country( 

955 timezones=["Indian/Mauritius"], 

956 alpha_2_code="MU", 

957 alpha_3_code="MUS", 

958 continent="Africa", 

959 name="Mauritius", 

960 capital="Port Louis", 

961 ), 

962 Country( 

963 timezones=["Indian/Maldives"], 

964 alpha_2_code="MV", 

965 alpha_3_code="MDV", 

966 continent="Asia", 

967 name="Maldives", 

968 capital="Mal\xc3\xa9", 

969 ), 

970 Country( 

971 timezones=["Africa/Blantyre"], 

972 alpha_2_code="MW", 

973 alpha_3_code="MWI", 

974 continent="Africa", 

975 name="Malawi", 

976 capital="Lilongwe", 

977 ), 

978 Country( 

979 timezones=[ 

980 "America/Mexico_City", 

981 "America/Cancun", 

982 "America/Merida", 

983 "America/Monterrey", 

984 "America/Mazatlan", 

985 "America/Chihuahua", 

986 "America/Hermosillo", 

987 "America/Tijuana", 

988 ], 

989 alpha_2_code="MX", 

990 alpha_3_code="MEX", 

991 continent="North America", 

992 name="Mexico", 

993 capital="Mexico City", 

994 ), 

995 Country( 

996 timezones=["Asia/Kuala_Lumpur", "Asia/Kuching"], 

997 alpha_2_code="MY", 

998 alpha_3_code="MYS", 

999 continent="Asia", 

1000 name="Malaysia", 

1001 capital="Kuala Lumpur", 

1002 ), 

1003 Country( 

1004 timezones=["Africa/Maputo"], 

1005 alpha_2_code="MZ", 

1006 alpha_3_code="MOZ", 

1007 continent="Africa", 

1008 name="Mozambique", 

1009 capital="Maputo", 

1010 ), 

1011 Country( 

1012 timezones=["Africa/Windhoek"], 

1013 alpha_2_code="NA", 

1014 alpha_3_code="NAM", 

1015 continent="Africa", 

1016 name="Namibia", 

1017 capital="Windhoek", 

1018 ), 

1019 Country( 

1020 timezones=["Africa/Niamey"], 

1021 alpha_2_code="NE", 

1022 alpha_3_code="NER", 

1023 continent="Africa", 

1024 name="Niger", 

1025 capital="Niamey", 

1026 ), 

1027 Country( 

1028 timezones=["Africa/Lagos"], 

1029 alpha_2_code="NG", 

1030 alpha_3_code="NGA", 

1031 continent="Africa", 

1032 name="Nigeria", 

1033 capital="Abuja", 

1034 ), 

1035 Country( 

1036 timezones=["America/Managua"], 

1037 alpha_2_code="NI", 

1038 alpha_3_code="NIC", 

1039 continent="North America", 

1040 name="Nicaragua", 

1041 capital="Managua", 

1042 ), 

1043 Country( 

1044 timezones=["Europe/Amsterdam"], 

1045 alpha_2_code="NL", 

1046 alpha_3_code="NLD", 

1047 continent="Europe", 

1048 name="Kingdom of the Netherlands", 

1049 capital="Amsterdam", 

1050 ), 

1051 Country( 

1052 timezones=["Europe/Oslo"], 

1053 alpha_2_code="NO", 

1054 alpha_3_code="NOR", 

1055 continent="Europe", 

1056 name="Norway", 

1057 capital="Oslo", 

1058 ), 

1059 Country( 

1060 timezones=["Asia/Katmandu"], 

1061 alpha_2_code="NP", 

1062 alpha_3_code="NPL", 

1063 continent="Asia", 

1064 name="Nepal", 

1065 capital="Kathmandu", 

1066 ), 

1067 Country( 

1068 timezones=["Pacific/Nauru"], 

1069 alpha_2_code="NR", 

1070 alpha_3_code="NRU", 

1071 continent="Oceania", 

1072 name="Nauru", 

1073 capital="Yaren", 

1074 ), 

1075 Country( 

1076 timezones=["Pacific/Auckland", "Pacific/Chatham"], 

1077 alpha_2_code="NZ", 

1078 alpha_3_code="NZL", 

1079 continent="Oceania", 

1080 name="New Zealand", 

1081 capital="Wellington", 

1082 ), 

1083 Country( 

1084 timezones=["Asia/Muscat"], 

1085 alpha_2_code="OM", 

1086 alpha_3_code="OMN", 

1087 continent="Asia", 

1088 name="Oman", 

1089 capital="Muscat", 

1090 ), 

1091 Country( 

1092 timezones=["America/Panama"], 

1093 alpha_2_code="PA", 

1094 alpha_3_code="PAN", 

1095 continent="North America", 

1096 name="Panama", 

1097 capital="Panama City", 

1098 ), 

1099 Country( 

1100 timezones=["America/Lima"], 

1101 alpha_2_code="PE", 

1102 alpha_3_code="PER", 

1103 continent="South America", 

1104 name="Peru", 

1105 capital="Lima", 

1106 ), 

1107 Country( 

1108 timezones=["Pacific/Port_Moresby"], 

1109 alpha_2_code="PG", 

1110 alpha_3_code="PNG", 

1111 continent="Oceania", 

1112 name="Papua New Guinea", 

1113 capital="Port Moresby", 

1114 ), 

1115 Country( 

1116 timezones=["Asia/Manila"], 

1117 alpha_2_code="PH", 

1118 alpha_3_code="PHL", 

1119 continent="Asia", 

1120 name="Philippines", 

1121 capital="Manila", 

1122 ), 

1123 Country( 

1124 timezones=["Asia/Karachi"], 

1125 alpha_2_code="PK", 

1126 alpha_3_code="PAK", 

1127 continent="Asia", 

1128 name="Pakistan", 

1129 capital="Islamabad", 

1130 ), 

1131 Country( 

1132 timezones=["Europe/Warsaw"], 

1133 alpha_2_code="PL", 

1134 alpha_3_code="POL", 

1135 continent="Europe", 

1136 name="Poland", 

1137 capital="Warsaw", 

1138 ), 

1139 Country( 

1140 timezones=["Europe/Lisbon", "Atlantic/Madeira", "Atlantic/Azores"], 

1141 alpha_2_code="PT", 

1142 alpha_3_code="PRT", 

1143 continent="Europe", 

1144 name="Portugal", 

1145 capital="Lisbon", 

1146 ), 

1147 Country( 

1148 timezones=["Pacific/Palau"], 

1149 alpha_2_code="PW", 

1150 alpha_3_code="PLW", 

1151 continent="Oceania", 

1152 name="Palau", 

1153 capital="Ngerulmud", 

1154 ), 

1155 Country( 

1156 timezones=["America/Asuncion"], 

1157 alpha_2_code="PY", 

1158 alpha_3_code="PRY", 

1159 continent="South America", 

1160 name="Paraguay", 

1161 capital="Asunci\xc3\xb3n", 

1162 ), 

1163 Country( 

1164 timezones=["Asia/Qatar"], 

1165 alpha_2_code="QA", 

1166 alpha_3_code="QAT", 

1167 continent="Asia", 

1168 name="Qatar", 

1169 capital="Doha", 

1170 ), 

1171 Country( 

1172 timezones=["Europe/Bucharest"], 

1173 alpha_2_code="RO", 

1174 alpha_3_code="ROU", 

1175 continent="Europe", 

1176 name="Romania", 

1177 capital="Bucharest", 

1178 ), 

1179 Country( 

1180 timezones=[ 

1181 "Europe/Kaliningrad", 

1182 "Europe/Moscow", 

1183 "Europe/Volgograd", 

1184 "Europe/Samara", 

1185 "Asia/Yekaterinburg", 

1186 "Asia/Omsk", 

1187 "Asia/Novosibirsk", 

1188 "Asia/Krasnoyarsk", 

1189 "Asia/Irkutsk", 

1190 "Asia/Yakutsk", 

1191 "Asia/Vladivostok", 

1192 "Asia/Sakhalin", 

1193 "Asia/Magadan", 

1194 "Asia/Kamchatka", 

1195 "Asia/Anadyr", 

1196 ], 

1197 alpha_2_code="RU", 

1198 alpha_3_code="RUS", 

1199 continent="Europe", 

1200 name="Russia", 

1201 capital="Moscow", 

1202 ), 

1203 Country( 

1204 timezones=["Africa/Kigali"], 

1205 alpha_2_code="RW", 

1206 alpha_3_code="RWA", 

1207 continent="Africa", 

1208 name="Rwanda", 

1209 capital="Kigali", 

1210 ), 

1211 Country( 

1212 timezones=["Asia/Riyadh"], 

1213 alpha_2_code="SA", 

1214 alpha_3_code="SAU", 

1215 continent="Asia", 

1216 name="Saudi Arabia", 

1217 capital="Riyadh", 

1218 ), 

1219 Country( 

1220 timezones=["Pacific/Guadalcanal"], 

1221 alpha_2_code="SB", 

1222 alpha_3_code="SLB", 

1223 continent="Oceania", 

1224 name="Solomon Islands", 

1225 capital="Honiara", 

1226 ), 

1227 Country( 

1228 timezones=["Indian/Mahe"], 

1229 alpha_2_code="SC", 

1230 alpha_3_code="SYC", 

1231 continent="Africa", 

1232 name="Seychelles", 

1233 capital="Victoria", 

1234 ), 

1235 Country( 

1236 timezones=["Africa/Khartoum"], 

1237 alpha_2_code="SD", 

1238 alpha_3_code="SDN", 

1239 continent="Africa", 

1240 name="Sudan", 

1241 capital="Khartoum", 

1242 ), 

1243 Country( 

1244 timezones=["Europe/Stockholm"], 

1245 alpha_2_code="SE", 

1246 alpha_3_code="SWE", 

1247 continent="Europe", 

1248 name="Sweden", 

1249 capital="Stockholm", 

1250 ), 

1251 Country( 

1252 timezones=["Asia/Singapore"], 

1253 alpha_2_code="SG", 

1254 alpha_3_code="SGP", 

1255 continent="Asia", 

1256 name="Singapore", 

1257 capital="Singapore", 

1258 ), 

1259 Country( 

1260 timezones=["Europe/Ljubljana"], 

1261 alpha_2_code="SI", 

1262 alpha_3_code="SVN", 

1263 continent="Europe", 

1264 name="Slovenia", 

1265 capital="Ljubljana", 

1266 ), 

1267 Country( 

1268 timezones=["Europe/Bratislava"], 

1269 alpha_2_code="SK", 

1270 alpha_3_code="SVK", 

1271 continent="Europe", 

1272 name="Slovakia", 

1273 capital="Bratislava", 

1274 ), 

1275 Country( 

1276 timezones=["Africa/Freetown"], 

1277 alpha_2_code="SL", 

1278 alpha_3_code="SLE", 

1279 continent="Africa", 

1280 name="Sierra Leone", 

1281 capital="Freetown", 

1282 ), 

1283 Country( 

1284 timezones=["Europe/San_Marino"], 

1285 alpha_2_code="SM", 

1286 alpha_3_code="SMR", 

1287 continent="Europe", 

1288 name="San Marino", 

1289 capital="San Marino", 

1290 ), 

1291 Country( 

1292 timezones=["Africa/Dakar"], 

1293 alpha_2_code="SN", 

1294 alpha_3_code="SEN", 

1295 continent="Africa", 

1296 name="Senegal", 

1297 capital="Dakar", 

1298 ), 

1299 Country( 

1300 timezones=["Africa/Mogadishu"], 

1301 alpha_2_code="SO", 

1302 alpha_3_code="SOM", 

1303 continent="Africa", 

1304 name="Somalia", 

1305 capital="Mogadishu", 

1306 ), 

1307 Country( 

1308 timezones=["America/Paramaribo"], 

1309 alpha_2_code="SR", 

1310 alpha_3_code="SUR", 

1311 continent="South America", 

1312 name="Suriname", 

1313 capital="Paramaribo", 

1314 ), 

1315 Country( 

1316 timezones=["Africa/Sao_Tome"], 

1317 alpha_2_code="ST", 

1318 alpha_3_code="STP", 

1319 continent="Africa", 

1320 name="S\xc3\xa3o Tom\xc3\xa9 and Pr\xc3\xadncipe", 

1321 capital="S\xc3\xa3o Tom\xc3\xa9", 

1322 ), 

1323 Country( 

1324 timezones=["Asia/Damascus"], 

1325 alpha_2_code="SY", 

1326 alpha_3_code="SYR", 

1327 continent="Asia", 

1328 name="Syria", 

1329 capital="Damascus", 

1330 ), 

1331 Country( 

1332 timezones=["Africa/Lome"], 

1333 alpha_2_code="TG", 

1334 alpha_3_code="TGO", 

1335 continent="Africa", 

1336 name="Togo", 

1337 capital="Lom\xc3\xa9", 

1338 ), 

1339 Country( 

1340 timezones=["Asia/Bangkok"], 

1341 alpha_2_code="TH", 

1342 alpha_3_code="THA", 

1343 continent="Asia", 

1344 name="Thailand", 

1345 capital="Bangkok", 

1346 ), 

1347 Country( 

1348 timezones=["Asia/Dushanbe"], 

1349 alpha_2_code="TJ", 

1350 alpha_3_code="TJK", 

1351 continent="Asia", 

1352 name="Tajikistan", 

1353 capital="Dushanbe", 

1354 ), 

1355 Country( 

1356 timezones=["Asia/Ashgabat"], 

1357 alpha_2_code="TM", 

1358 alpha_3_code="TKM", 

1359 continent="Asia", 

1360 name="Turkmenistan", 

1361 capital="Ashgabat", 

1362 ), 

1363 Country( 

1364 timezones=["Africa/Tunis"], 

1365 alpha_2_code="TN", 

1366 alpha_3_code="TUN", 

1367 continent="Africa", 

1368 name="Tunisia", 

1369 capital="Tunis", 

1370 ), 

1371 Country( 

1372 timezones=["Pacific/Tongatapu"], 

1373 alpha_2_code="TO", 

1374 alpha_3_code="TON", 

1375 continent="Oceania", 

1376 name="Tonga", 

1377 capital="Nuku\xca\xbbalofa", 

1378 ), 

1379 Country( 

1380 timezones=["Europe/Istanbul"], 

1381 alpha_2_code="TR", 

1382 alpha_3_code="TUR", 

1383 continent="Asia", 

1384 name="Turkey", 

1385 capital="Ankara", 

1386 ), 

1387 Country( 

1388 timezones=["America/Port_of_Spain"], 

1389 alpha_2_code="TT", 

1390 alpha_3_code="TTO", 

1391 continent="North America", 

1392 name="Trinidad and Tobago", 

1393 capital="Port of Spain", 

1394 ), 

1395 Country( 

1396 timezones=["Pacific/Funafuti"], 

1397 alpha_2_code="TV", 

1398 alpha_3_code="TUV", 

1399 continent="Oceania", 

1400 name="Tuvalu", 

1401 capital="Funafuti", 

1402 ), 

1403 Country( 

1404 timezones=["Africa/Dar_es_Salaam"], 

1405 alpha_2_code="TZ", 

1406 alpha_3_code="TZA", 

1407 continent="Africa", 

1408 name="Tanzania", 

1409 capital="Dodoma", 

1410 ), 

1411 Country( 

1412 timezones=[ 

1413 "Europe/Kiev", 

1414 "Europe/Uzhgorod", 

1415 "Europe/Zaporozhye", 

1416 "Europe/Simferopol", 

1417 ], 

1418 alpha_2_code="UA", 

1419 alpha_3_code="UKR", 

1420 continent="Europe", 

1421 name="Ukraine", 

1422 capital="Kiev", 

1423 ), 

1424 Country( 

1425 timezones=["Africa/Kampala"], 

1426 alpha_2_code="UG", 

1427 alpha_3_code="UGA", 

1428 continent="Africa", 

1429 name="Uganda", 

1430 capital="Kampala", 

1431 ), 

1432 Country( 

1433 timezones=[ 

1434 "America/New_York", 

1435 "America/Detroit", 

1436 "America/Kentucky/Louisville", 

1437 "America/Kentucky/Monticello", 

1438 "America/Indiana/Indianapolis", 

1439 "America/Indiana/Marengo", 

1440 "America/Indiana/Knox", 

1441 "America/Indiana/Vevay", 

1442 "America/Chicago", 

1443 "America/Indiana/Vincennes", 

1444 "America/Indiana/Petersburg", 

1445 "America/Menominee", 

1446 "America/North_Dakota/Center", 

1447 "America/North_Dakota/New_Salem", 

1448 "America/Denver", 

1449 "America/Boise", 

1450 "America/Shiprock", 

1451 "America/Phoenix", 

1452 "America/Los_Angeles", 

1453 "America/Anchorage", 

1454 "America/Juneau", 

1455 "America/Yakutat", 

1456 "America/Nome", 

1457 "America/Adak", 

1458 "Pacific/Honolulu", 

1459 ], 

1460 alpha_2_code="US", 

1461 alpha_3_code="USA", 

1462 continent="North America", 

1463 name="United States", 

1464 capital="Washington, D.C.", 

1465 ), 

1466 Country( 

1467 timezones=["America/Montevideo"], 

1468 alpha_2_code="UY", 

1469 alpha_3_code="URY", 

1470 continent="South America", 

1471 name="Uruguay", 

1472 capital="Montevideo", 

1473 ), 

1474 Country( 

1475 timezones=["Asia/Samarkand", "Asia/Tashkent"], 

1476 alpha_2_code="UZ", 

1477 alpha_3_code="UZB", 

1478 continent="Asia", 

1479 name="Uzbekistan", 

1480 capital="Tashkent", 

1481 ), 

1482 Country( 

1483 timezones=["Europe/Vatican"], 

1484 alpha_2_code="VA", 

1485 alpha_3_code="VAT", 

1486 continent="Europe", 

1487 name="Vatican City", 

1488 capital="Vatican City", 

1489 ), 

1490 Country( 

1491 timezones=["America/Caracas"], 

1492 alpha_2_code="VE", 

1493 alpha_3_code="VEN", 

1494 continent="South America", 

1495 name="Venezuela", 

1496 capital="Caracas", 

1497 ), 

1498 Country( 

1499 timezones=["Asia/Saigon"], 

1500 alpha_2_code="VN", 

1501 alpha_3_code="VNM", 

1502 continent="Asia", 

1503 name="Vietnam", 

1504 capital="Hanoi", 

1505 ), 

1506 Country( 

1507 timezones=["Pacific/Efate"], 

1508 alpha_2_code="VU", 

1509 alpha_3_code="VUT", 

1510 continent="Oceania", 

1511 name="Vanuatu", 

1512 capital="Port Vila", 

1513 ), 

1514 Country( 

1515 timezones=["Asia/Aden"], 

1516 alpha_2_code="YE", 

1517 alpha_3_code="YEM", 

1518 continent="Asia", 

1519 name="Yemen", 

1520 capital="Sana'a", 

1521 ), 

1522 Country( 

1523 timezones=["Africa/Lusaka"], 

1524 alpha_2_code="ZM", 

1525 alpha_3_code="ZMB", 

1526 continent="Africa", 

1527 name="Zambia", 

1528 capital="Lusaka", 

1529 ), 

1530 Country( 

1531 timezones=["Africa/Harare"], 

1532 alpha_2_code="ZW", 

1533 alpha_3_code="ZWE", 

1534 continent="Africa", 

1535 name="Zimbabwe", 

1536 capital="Harare", 

1537 ), 

1538 Country( 

1539 timezones=["Africa/Algiers"], 

1540 alpha_2_code="DZ", 

1541 alpha_3_code="DZA", 

1542 continent="Africa", 

1543 name="Algeria", 

1544 capital="Algiers", 

1545 ), 

1546 Country( 

1547 timezones=["Europe/Sarajevo"], 

1548 alpha_2_code="BA", 

1549 alpha_3_code="BIH", 

1550 continent="Europe", 

1551 name="Bosnia and Herzegovina", 

1552 capital="Sarajevo", 

1553 ), 

1554 Country( 

1555 timezones=["Asia/Phnom_Penh"], 

1556 alpha_2_code="KH", 

1557 alpha_3_code="KHM", 

1558 continent="Asia", 

1559 name="Cambodia", 

1560 capital="Phnom Penh", 

1561 ), 

1562 Country( 

1563 timezones=["Africa/Bangui"], 

1564 alpha_2_code="CF", 

1565 alpha_3_code="CAF", 

1566 continent="Africa", 

1567 name="Central African Republic", 

1568 capital="Bangui", 

1569 ), 

1570 Country( 

1571 timezones=["Africa/Ndjamena"], 

1572 alpha_2_code="TD", 

1573 alpha_3_code="TCD", 

1574 continent="Africa", 

1575 name="Chad", 

1576 capital="N'Djamena", 

1577 ), 

1578 Country( 

1579 timezones=["Indian/Comoro"], 

1580 alpha_2_code="KM", 

1581 alpha_3_code="COM", 

1582 continent="Africa", 

1583 name="Comoros", 

1584 capital="Moroni", 

1585 ), 

1586 Country( 

1587 timezones=["Europe/Zagreb"], 

1588 alpha_2_code="HR", 

1589 alpha_3_code="HRV", 

1590 continent="Europe", 

1591 name="Croatia", 

1592 capital="Zagreb", 

1593 ), 

1594 Country( 

1595 timezones=["Asia/Dili"], 

1596 alpha_2_code="TL", 

1597 alpha_3_code="TLS", 

1598 continent="Asia", 

1599 name="East Timor", 

1600 capital="Dili", 

1601 ), 

1602 Country( 

1603 timezones=["America/El_Salvador"], 

1604 alpha_2_code="SV", 

1605 alpha_3_code="SLV", 

1606 continent="North America", 

1607 name="El Salvador", 

1608 capital="San Salvador", 

1609 ), 

1610 Country( 

1611 timezones=["Africa/Malabo"], 

1612 alpha_2_code="GQ", 

1613 alpha_3_code="GNQ", 

1614 continent="Africa", 

1615 name="Equatorial Guinea", 

1616 capital="Malabo", 

1617 ), 

1618 Country( 

1619 timezones=["America/Grenada"], 

1620 alpha_2_code="GD", 

1621 alpha_3_code="GRD", 

1622 continent="North America", 

1623 name="Grenada", 

1624 capital="St. George's", 

1625 ), 

1626 Country( 

1627 timezones=[ 

1628 "Asia/Almaty", 

1629 "Asia/Qyzylorda", 

1630 "Asia/Aqtobe", 

1631 "Asia/Aqtau", 

1632 "Asia/Oral", 

1633 ], 

1634 alpha_2_code="KZ", 

1635 alpha_3_code="KAZ", 

1636 continent="Asia", 

1637 name="Kazakhstan", 

1638 capital="Astana", 

1639 ), 

1640 Country( 

1641 timezones=["Asia/Vientiane"], 

1642 alpha_2_code="LA", 

1643 alpha_3_code="LAO", 

1644 continent="Asia", 

1645 name="Laos", 

1646 capital="Vientiane", 

1647 ), 

1648 Country( 

1649 timezones=["Pacific/Truk", "Pacific/Ponape", "Pacific/Kosrae"], 

1650 alpha_2_code="FM", 

1651 alpha_3_code="FSM", 

1652 continent="Oceania", 

1653 name="Federated States of Micronesia", 

1654 capital="Palikir", 

1655 ), 

1656 Country( 

1657 timezones=["Europe/Chisinau"], 

1658 alpha_2_code="MD", 

1659 alpha_3_code="MDA", 

1660 continent="Europe", 

1661 name="Moldova", 

1662 capital="Chi\xc5\x9fin\xc4\x83u", 

1663 ), 

1664 Country( 

1665 timezones=["Europe/Monaco"], 

1666 alpha_2_code="MC", 

1667 alpha_3_code="MCO", 

1668 continent="Europe", 

1669 name="Monaco", 

1670 capital="Monaco", 

1671 ), 

1672 Country( 

1673 timezones=["Europe/Podgorica"], 

1674 alpha_2_code="ME", 

1675 alpha_3_code="MNE", 

1676 continent="Europe", 

1677 name="Montenegro", 

1678 capital="Podgorica", 

1679 ), 

1680 Country( 

1681 timezones=["Africa/Casablanca"], 

1682 alpha_2_code="MA", 

1683 alpha_3_code="MAR", 

1684 continent="Africa", 

1685 name="Morocco", 

1686 capital="Rabat", 

1687 ), 

1688 Country( 

1689 timezones=["America/St_Kitts"], 

1690 alpha_2_code="KN", 

1691 alpha_3_code="KNA", 

1692 continent="North America", 

1693 name="Saint Kitts and Nevis", 

1694 capital="Basseterre", 

1695 ), 

1696 Country( 

1697 timezones=["America/St_Lucia"], 

1698 alpha_2_code="LC", 

1699 alpha_3_code="LCA", 

1700 continent="North America", 

1701 name="Saint Lucia", 

1702 capital="Castries", 

1703 ), 

1704 Country( 

1705 timezones=["America/St_Vincent"], 

1706 alpha_2_code="VC", 

1707 alpha_3_code="VCT", 

1708 continent="North America", 

1709 name="Saint Vincent and the Grenadines", 

1710 capital="Kingstown", 

1711 ), 

1712 Country( 

1713 timezones=["Pacific/Apia"], 

1714 alpha_2_code="WS", 

1715 alpha_3_code="WSM", 

1716 continent="Oceania", 

1717 name="Samoa", 

1718 capital="Apia", 

1719 ), 

1720 Country( 

1721 timezones=["Europe/Belgrade"], 

1722 alpha_2_code="RS", 

1723 alpha_3_code="SRB", 

1724 continent="Europe", 

1725 name="Serbia", 

1726 capital="Belgrade", 

1727 ), 

1728 Country( 

1729 timezones=["Africa/Johannesburg"], 

1730 alpha_2_code="ZA", 

1731 alpha_3_code="ZAF", 

1732 continent="Africa", 

1733 name="South Africa", 

1734 capital="Pretoria", 

1735 ), 

1736 Country( 

1737 timezones=["Europe/Madrid", "Africa/Ceuta", "Atlantic/Canary"], 

1738 alpha_2_code="ES", 

1739 alpha_3_code="ESP", 

1740 continent="Europe", 

1741 name="Spain", 

1742 capital="Madrid", 

1743 ), 

1744 Country( 

1745 timezones=["Asia/Colombo"], 

1746 alpha_2_code="LK", 

1747 alpha_3_code="LKA", 

1748 continent="Asia", 

1749 name="Sri Lanka", 

1750 capital="Sri Jayewardenepura Kotte", 

1751 ), 

1752 Country( 

1753 timezones=["Africa/Mbabane"], 

1754 alpha_2_code="SZ", 

1755 alpha_3_code="SWZ", 

1756 continent="Africa", 

1757 name="Swaziland", 

1758 capital="Mbabane", 

1759 ), 

1760 Country( 

1761 timezones=["Europe/Zurich"], 

1762 alpha_2_code="CH", 

1763 alpha_3_code="CHE", 

1764 continent="Europe", 

1765 name="Switzerland", 

1766 capital="Bern", 

1767 ), 

1768 Country( 

1769 timezones=["Asia/Dubai"], 

1770 alpha_2_code="AE", 

1771 alpha_3_code="ARE", 

1772 continent="Asia", 

1773 name="United Arab Emirates", 

1774 capital="Abu Dhabi", 

1775 ), 

1776 Country( 

1777 timezones=["Europe/London"], 

1778 alpha_2_code="GB", 

1779 alpha_3_code="GBR", 

1780 continent="Europe", 

1781 name="United Kingdom", 

1782 capital="London", 

1783 ), 

1784 Country( 

1785 timezones=["Asia/Taipei"], 

1786 alpha_2_code="TW", 

1787 alpha_3_code="TWN", 

1788 continent="Asia", 

1789 name="Taiwan", 

1790 capital="Taipei", 

1791 ), 

1792 Country( 

1793 timezones=["Asia/Gaza", "Asia/Hebron"], 

1794 alpha_2_code="PS", 

1795 alpha_3_code="PSE", 

1796 continent="Asia", 

1797 name="Palestine", 

1798 capital="Ramallah", 

1799 ), 

1800 ] 

1801 

1802 regex = re.compile(timedelta_pattern) 

1803 

1804 def unix_time( 

1805 self, 

1806 end_datetime: Optional[DateParseType] = None, 

1807 start_datetime: Optional[DateParseType] = None, 

1808 ) -> int: 

1809 """ 

1810 Get a timestamp between January 1, 1970 and now, unless passed 

1811 explicit start_datetime or end_datetime values. 

1812 :example: 1061306726 

1813 """ 

1814 start_datetime = self._parse_start_datetime(start_datetime) 

1815 end_datetime = self._parse_end_datetime(end_datetime) 

1816 return self.generator.random.randint(start_datetime, end_datetime) 

1817 

1818 def time_delta(self, end_datetime: Optional[DateParseType] = None) -> timedelta: 

1819 """ 

1820 Get a timedelta object 

1821 """ 

1822 start_datetime = self._parse_start_datetime("now") 

1823 end_datetime = self._parse_end_datetime(end_datetime) 

1824 seconds = end_datetime - start_datetime 

1825 

1826 ts = self.generator.random.randint(*sorted([0, seconds])) 

1827 return timedelta(seconds=ts) 

1828 

1829 def date_time( 

1830 self, 

1831 tzinfo: Optional[TzInfo] = None, 

1832 end_datetime: Optional[DateParseType] = None, 

1833 ) -> datetime: 

1834 """ 

1835 Get a datetime object for a date between January 1, 1970 and now 

1836 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

1837 :example: datetime('2005-08-16 20:39:21') 

1838 :return: datetime 

1839 """ 

1840 # NOTE: On windows, the lowest value you can get from windows is 86400 

1841 # on the first day. Known python issue: 

1842 # https://bugs.python.org/issue30684 

1843 return datetime(1970, 1, 1, tzinfo=tzinfo) + timedelta(seconds=self.unix_time(end_datetime=end_datetime)) 

1844 

1845 def date_time_ad( 

1846 self, 

1847 tzinfo: Optional[TzInfo] = None, 

1848 end_datetime: Optional[DateParseType] = None, 

1849 start_datetime: Optional[DateParseType] = None, 

1850 ) -> datetime: 

1851 """ 

1852 Get a datetime object for a date between January 1, 001 and now 

1853 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

1854 :example: datetime('1265-03-22 21:15:52') 

1855 :return: datetime 

1856 """ 

1857 

1858 # 1970-01-01 00:00:00 UTC minus 62135596800 seconds is 

1859 # 0001-01-01 00:00:00 UTC. Since _parse_end_datetime() is used 

1860 # elsewhere where a default value of 0 is expected, we can't 

1861 # simply change that class method to use this magic number as a 

1862 # default value when None is provided. 

1863 

1864 start_time = -62135596800 if start_datetime is None else self._parse_start_datetime(start_datetime) 

1865 end_datetime = self._parse_end_datetime(end_datetime) 

1866 

1867 ts = self.generator.random.randint(start_time, end_datetime) 

1868 # NOTE: using datetime.fromtimestamp(ts) directly will raise 

1869 # a "ValueError: timestamp out of range for platform time_t" 

1870 # on some platforms due to system C functions; 

1871 # see http://stackoverflow.com/a/10588133/2315612 

1872 # NOTE: On windows, the lowest value you can get from windows is 86400 

1873 # on the first day. Known python issue: 

1874 # https://bugs.python.org/issue30684 

1875 return datetime(1970, 1, 1, tzinfo=tzinfo) + timedelta(seconds=ts) 

1876 

1877 def iso8601( 

1878 self, 

1879 tzinfo: Optional[TzInfo] = None, 

1880 end_datetime: Optional[DateParseType] = None, 

1881 sep: str = "T", 

1882 timespec: str = "auto", 

1883 ) -> str: 

1884 """ 

1885 Get a timestamp in ISO 8601 format (or one of its profiles). 

1886 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

1887 :param sep: separator between date and time, defaults to 'T' 

1888 :param timespec: format specifier for the time part, defaults to 'auto' - see datetime.isoformat() documentation 

1889 :example: '2003-10-21T16:05:52+0000' 

1890 """ 

1891 return self.date_time(tzinfo, end_datetime=end_datetime).isoformat(sep, timespec) 

1892 

1893 def date(self, pattern: str = "%Y-%m-%d", end_datetime: Optional[DateParseType] = None) -> str: 

1894 """ 

1895 Get a date string between January 1, 1970 and now. 

1896 

1897 :param pattern: Format of the date (year-month-day by default) 

1898 :example: '2008-11-27' 

1899 :return: Date 

1900 """ 

1901 return self.date_time(end_datetime=end_datetime).strftime(pattern) 

1902 

1903 def date_object(self, end_datetime: Optional[datetime] = None) -> dtdate: 

1904 """ 

1905 Get a date object between January 1, 1970 and now 

1906 :example: datetime.date(2016, 9, 20) 

1907 """ 

1908 return self.date_time(end_datetime=end_datetime).date() 

1909 

1910 def time(self, pattern: str = "%H:%M:%S", end_datetime: Optional[DateParseType] = None) -> str: 

1911 """ 

1912 Get a time string (24h format by default) 

1913 :param pattern: format 

1914 :example: '15:02:34' 

1915 """ 

1916 return self.date_time(end_datetime=end_datetime).time().strftime(pattern) 

1917 

1918 def time_object(self, end_datetime: Optional[DateParseType] = None) -> dttime: 

1919 """ 

1920 Get a time object 

1921 :example: datetime.time(15, 56, 56, 772876) 

1922 """ 

1923 return self.date_time(end_datetime=end_datetime).time() 

1924 

1925 @classmethod 

1926 def _parse_start_datetime(cls, value: Optional[DateParseType]) -> int: 

1927 if value is None: 

1928 return 0 

1929 

1930 return cls._parse_date_time(value) 

1931 

1932 @classmethod 

1933 def _parse_end_datetime(cls, value: Optional[DateParseType]) -> int: 

1934 if value is None: 

1935 return datetime_to_timestamp(datetime.now()) 

1936 

1937 return cls._parse_date_time(value) 

1938 

1939 @classmethod 

1940 def _parse_date_string(cls, value: str) -> Dict[str, float]: 

1941 parts = cls.regex.match(value) 

1942 if not parts: 1942 ↛ 1943line 1942 didn't jump to line 1943, because the condition on line 1942 was never true

1943 raise ParseError(f"Can't parse date string `{value}`") 

1944 parts = parts.groupdict() 

1945 time_params: Dict[str, float] = {} 

1946 for (name_, param_) in parts.items(): 

1947 if param_: 

1948 time_params[name_] = int(param_) 

1949 

1950 if "years" in time_params: 

1951 if "days" not in time_params: 1951 ↛ 1953line 1951 didn't jump to line 1953, because the condition on line 1951 was never false

1952 time_params["days"] = 0 

1953 time_params["days"] += 365.24 * time_params.pop("years") 

1954 if "months" in time_params: 1954 ↛ 1955line 1954 didn't jump to line 1955, because the condition on line 1954 was never true

1955 if "days" not in time_params: 

1956 time_params["days"] = 0 

1957 time_params["days"] += 30.42 * time_params.pop("months") 

1958 

1959 if not time_params: 1959 ↛ 1960line 1959 didn't jump to line 1960, because the condition on line 1959 was never true

1960 raise ParseError(f"Can't parse date string `{value}`") 

1961 return time_params 

1962 

1963 @classmethod 

1964 def _parse_timedelta(cls, value: Union[timedelta, str, float]) -> Union[float, int]: 

1965 if isinstance(value, timedelta): 

1966 return value.total_seconds() 

1967 if isinstance(value, str): 

1968 time_params = cls._parse_date_string(value) 

1969 return timedelta(**time_params).total_seconds() # type: ignore 

1970 if isinstance(value, (int, float)): 

1971 return value 

1972 raise ParseError(f"Invalid format for timedelta {value!r}") 

1973 

1974 @classmethod 

1975 def _parse_date_time(cls, value: DateParseType, tzinfo: Optional[TzInfo] = None) -> int: 

1976 if isinstance(value, (datetime, dtdate)): 1976 ↛ 1978line 1976 didn't jump to line 1978, because the condition on line 1976 was never false

1977 return datetime_to_timestamp(value) 

1978 now = datetime.now(tzinfo) 

1979 if isinstance(value, timedelta): 

1980 return datetime_to_timestamp(now + value) 

1981 if isinstance(value, str): 

1982 if value == "now": 

1983 return datetime_to_timestamp(datetime.now(tzinfo)) 

1984 time_params = cls._parse_date_string(value) 

1985 return datetime_to_timestamp(now + timedelta(**time_params)) # type: ignore 

1986 if isinstance(value, int): 

1987 return value 

1988 raise ParseError(f"Invalid format for date {value!r}") 

1989 

1990 @classmethod 

1991 def _parse_date(cls, value: DateParseType) -> dtdate: 

1992 if isinstance(value, datetime): 1992 ↛ 1993line 1992 didn't jump to line 1993, because the condition on line 1992 was never true

1993 return value.date() 

1994 elif isinstance(value, dtdate): 1994 ↛ 1995line 1994 didn't jump to line 1995, because the condition on line 1994 was never true

1995 return value 

1996 today = dtdate.today() 

1997 if isinstance(value, timedelta): 1997 ↛ 1998line 1997 didn't jump to line 1998, because the condition on line 1997 was never true

1998 return today + value 

1999 if isinstance(value, str): 1999 ↛ 2004line 1999 didn't jump to line 2004, because the condition on line 1999 was never false

2000 if value in ("today", "now"): 

2001 return today 

2002 time_params = cls._parse_date_string(value) 

2003 return today + timedelta(**time_params) # type: ignore 

2004 if isinstance(value, int): 

2005 return today + timedelta(value) 

2006 raise ParseError(f"Invalid format for date {value!r}") 

2007 

2008 def date_time_between( 

2009 self, 

2010 start_date: DateParseType = "-30y", 

2011 end_date: DateParseType = "now", 

2012 tzinfo: Optional[TzInfo] = None, 

2013 ) -> datetime: 

2014 """ 

2015 Get a datetime object based on a random date between two given dates. 

2016 Accepts date strings that can be recognized by strtotime(). 

2017 

2018 :param start_date: Defaults to 30 years ago 

2019 :param end_date: Defaults to "now" 

2020 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2021 :example: datetime('1999-02-02 11:42:52') 

2022 :return: datetime 

2023 """ 

2024 start_date = self._parse_date_time(start_date, tzinfo=tzinfo) 

2025 end_date = self._parse_date_time(end_date, tzinfo=tzinfo) 

2026 if end_date - start_date <= 1: 

2027 ts = start_date + self.generator.random.random() 

2028 else: 

2029 ts = self.generator.random.randint(start_date, end_date) 

2030 if tzinfo is None: 

2031 return datetime(1970, 1, 1, tzinfo=tzinfo) + timedelta(seconds=ts) 

2032 else: 

2033 return (datetime(1970, 1, 1, tzinfo=tzutc()) + timedelta(seconds=ts)).astimezone(tzinfo) 

2034 

2035 def date_between(self, start_date: DateParseType = "-30y", end_date: DateParseType = "today") -> dtdate: 

2036 """ 

2037 Get a Date object based on a random date between two given dates. 

2038 Accepts date strings that can be recognized by strtotime(). 

2039 

2040 :param start_date: Defaults to 30 years ago 

2041 :param end_date: Defaults to "today" 

2042 :example: Date('1999-02-02') 

2043 :return: Date 

2044 """ 

2045 

2046 start_date = self._parse_date(start_date) 

2047 end_date = self._parse_date(end_date) 

2048 return self.date_between_dates(date_start=start_date, date_end=end_date) 

2049 

2050 def future_datetime(self, end_date: DateParseType = "+30d", tzinfo: Optional[TzInfo] = None) -> datetime: 

2051 """ 

2052 Get a datetime object based on a random date between 1 second form now 

2053 and a given date. 

2054 Accepts date strings that can be recognized by strtotime(). 

2055 

2056 :param end_date: Defaults to "+30d" 

2057 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2058 :example: datetime('1999-02-02 11:42:52') 

2059 :return: datetime 

2060 """ 

2061 return self.date_time_between(start_date="+1s", end_date=end_date, tzinfo=tzinfo) 

2062 

2063 def future_date(self, end_date: DateParseType = "+30d", tzinfo: Optional[TzInfo] = None) -> dtdate: 

2064 """ 

2065 Get a Date object based on a random date between 1 day from now and a 

2066 given date. 

2067 Accepts date strings that can be recognized by strtotime(). 

2068 

2069 :param end_date: Defaults to "+30d" 

2070 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2071 :example: dtdate('2030-01-01') 

2072 :return: dtdate 

2073 """ 

2074 return self.date_between(start_date="+1d", end_date=end_date) 

2075 

2076 def past_datetime(self, start_date: DateParseType = "-30d", tzinfo: Optional[TzInfo] = None) -> datetime: 

2077 """ 

2078 Get a datetime object based on a random date between a given date and 1 

2079 second ago. 

2080 Accepts date strings that can be recognized by strtotime(). 

2081 

2082 :param start_date: Defaults to "-30d" 

2083 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2084 :example: datetime('1999-02-02 11:42:52') 

2085 :return: datetime 

2086 """ 

2087 return self.date_time_between(start_date=start_date, end_date="-1s", tzinfo=tzinfo) 

2088 

2089 def past_date(self, start_date: DateParseType = "-30d", tzinfo: Optional[TzInfo] = None) -> dtdate: 

2090 """ 

2091 Get a Date object based on a random date between a given date and 1 day 

2092 ago. 

2093 Accepts date strings that can be recognized by strtotime(). 

2094 

2095 :param start_date: Defaults to "-30d" 

2096 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2097 :example: dtdate('1999-02-02') 

2098 :return: dtdate 

2099 """ 

2100 return self.date_between(start_date=start_date, end_date="-1d") 

2101 

2102 def date_time_between_dates( 

2103 self, 

2104 datetime_start: Optional[DateParseType] = None, 

2105 datetime_end: Optional[DateParseType] = None, 

2106 tzinfo: Optional[TzInfo] = None, 

2107 ) -> datetime: 

2108 """ 

2109 Takes two datetime objects and returns a random datetime between the two 

2110 given datetimes. 

2111 Accepts datetime objects. 

2112 

2113 :param datetime_start: datetime 

2114 :param datetime_end: datetime 

2115 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2116 :example: datetime('1999-02-02 11:42:52') 

2117 :return: datetime 

2118 """ 

2119 datetime_start_ = ( 

2120 datetime_to_timestamp(datetime.now(tzinfo)) 

2121 if datetime_start is None 

2122 else self._parse_date_time(datetime_start) 

2123 ) 

2124 datetime_end_ = ( 

2125 datetime_to_timestamp(datetime.now(tzinfo)) if datetime_end is None else self._parse_date_time(datetime_end) 

2126 ) 

2127 

2128 timestamp = self.generator.random.randint(datetime_start_, datetime_end_) 

2129 try: 

2130 if tzinfo is None: 2130 ↛ 2137line 2130 didn't jump to line 2137, because the condition on line 2130 was never false

2131 pick = convert_timestamp_to_datetime(timestamp, tzlocal()) 

2132 try: 

2133 pick = pick.astimezone(tzutc()).replace(tzinfo=None) 

2134 except OSError: 

2135 pass 

2136 else: 

2137 pick = datetime.fromtimestamp(timestamp, tzinfo) 

2138 except OverflowError: 

2139 raise OverflowError( 

2140 "You specified an end date with a timestamp bigger than the maximum allowed on this" 

2141 " system. Please specify an earlier date.", 

2142 ) 

2143 return pick 

2144 

2145 def date_between_dates( 

2146 self, 

2147 date_start: Optional[DateParseType] = None, 

2148 date_end: Optional[DateParseType] = None, 

2149 ) -> dtdate: 

2150 """ 

2151 Takes two Date objects and returns a random date between the two given dates. 

2152 Accepts Date or datetime objects 

2153 

2154 :param date_start: Date 

2155 :param date_end: Date 

2156 :return: Date 

2157 """ 

2158 return self.date_time_between_dates(date_start, date_end).date() 

2159 

2160 def date_time_this_century( 

2161 self, 

2162 before_now: bool = True, 

2163 after_now: bool = False, 

2164 tzinfo: Optional[TzInfo] = None, 

2165 ) -> datetime: 

2166 """ 

2167 Gets a datetime object for the current century. 

2168 

2169 :param before_now: include days in current century before today 

2170 :param after_now: include days in current century after today 

2171 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2172 :example: datetime('2012-04-04 11:02:02') 

2173 :return: datetime 

2174 """ 

2175 now = datetime.now(tzinfo) 

2176 this_century_start = datetime(now.year - (now.year % 100), 1, 1, tzinfo=tzinfo) 

2177 next_century_start = datetime(min(this_century_start.year + 100, MAXYEAR), 1, 1, tzinfo=tzinfo) 

2178 

2179 if before_now and after_now: 

2180 return self.date_time_between_dates(this_century_start, next_century_start, tzinfo) 

2181 elif not before_now and after_now: 

2182 return self.date_time_between_dates(now, next_century_start, tzinfo) 

2183 elif not after_now and before_now: 

2184 return self.date_time_between_dates(this_century_start, now, tzinfo) 

2185 else: 

2186 return now 

2187 

2188 def date_time_this_decade( 

2189 self, 

2190 before_now: bool = True, 

2191 after_now: bool = False, 

2192 tzinfo: Optional[TzInfo] = None, 

2193 ) -> datetime: 

2194 """ 

2195 Gets a datetime object for the decade year. 

2196 

2197 :param before_now: include days in current decade before today 

2198 :param after_now: include days in current decade after today 

2199 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2200 :example: datetime('2012-04-04 11:02:02') 

2201 :return: datetime 

2202 """ 

2203 now = datetime.now(tzinfo) 

2204 this_decade_start = datetime(now.year - (now.year % 10), 1, 1, tzinfo=tzinfo) 

2205 next_decade_start = datetime(min(this_decade_start.year + 10, MAXYEAR), 1, 1, tzinfo=tzinfo) 

2206 

2207 if before_now and after_now: 

2208 return self.date_time_between_dates(this_decade_start, next_decade_start, tzinfo) 

2209 elif not before_now and after_now: 

2210 return self.date_time_between_dates(now, next_decade_start, tzinfo) 

2211 elif not after_now and before_now: 

2212 return self.date_time_between_dates(this_decade_start, now, tzinfo) 

2213 else: 

2214 return now 

2215 

2216 def date_time_this_year( 

2217 self, 

2218 before_now: bool = True, 

2219 after_now: bool = False, 

2220 tzinfo: Optional[TzInfo] = None, 

2221 ) -> datetime: 

2222 """ 

2223 Gets a datetime object for the current year. 

2224 

2225 :param before_now: include days in current year before today 

2226 :param after_now: include days in current year after today 

2227 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2228 :example: datetime('2012-04-04 11:02:02') 

2229 :return: datetime 

2230 """ 

2231 now = datetime.now(tzinfo) 

2232 this_year_start = now.replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0) 

2233 next_year_start = datetime(now.year + 1, 1, 1, tzinfo=tzinfo) 

2234 

2235 if before_now and after_now: 

2236 return self.date_time_between_dates(this_year_start, next_year_start, tzinfo) 

2237 elif not before_now and after_now: 

2238 return self.date_time_between_dates(now, next_year_start, tzinfo) 

2239 elif not after_now and before_now: 

2240 return self.date_time_between_dates(this_year_start, now, tzinfo) 

2241 else: 

2242 return now 

2243 

2244 def date_time_this_month( 

2245 self, 

2246 before_now: bool = True, 

2247 after_now: bool = False, 

2248 tzinfo: Optional[TzInfo] = None, 

2249 ) -> datetime: 

2250 """ 

2251 Gets a datetime object for the current month. 

2252 

2253 :param before_now: include days in current month before today 

2254 :param after_now: include days in current month after today 

2255 :param tzinfo: timezone, instance of datetime.tzinfo subclass 

2256 :example: datetime('2012-04-04 11:02:02') 

2257 :return: datetime 

2258 """ 

2259 now = datetime.now(tzinfo) 

2260 this_month_start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0) 

2261 

2262 next_month_start = this_month_start + relativedelta.relativedelta(months=1) 

2263 if before_now and after_now: 

2264 return self.date_time_between_dates(this_month_start, next_month_start, tzinfo) 

2265 elif not before_now and after_now: 

2266 return self.date_time_between_dates(now, next_month_start, tzinfo) 

2267 elif not after_now and before_now: 

2268 return self.date_time_between_dates(this_month_start, now, tzinfo) 

2269 else: 

2270 return now 

2271 

2272 def date_this_century(self, before_today: bool = True, after_today: bool = False) -> dtdate: 

2273 """ 

2274 Gets a Date object for the current century. 

2275 

2276 :param before_today: include days in current century before today 

2277 :param after_today: include days in current century after today 

2278 :example: Date('2012-04-04') 

2279 :return: Date 

2280 """ 

2281 today = dtdate.today() 

2282 this_century_start = dtdate(today.year - (today.year % 100), 1, 1) 

2283 next_century_start = dtdate(this_century_start.year + 100, 1, 1) 

2284 

2285 if before_today and after_today: 

2286 return self.date_between_dates(this_century_start, next_century_start) 

2287 elif not before_today and after_today: 

2288 return self.date_between_dates(today, next_century_start) 

2289 elif not after_today and before_today: 

2290 return self.date_between_dates(this_century_start, today) 

2291 else: 

2292 return today 

2293 

2294 def date_this_decade(self, before_today: bool = True, after_today: bool = False) -> dtdate: 

2295 """ 

2296 Gets a Date object for the decade year. 

2297 

2298 :param before_today: include days in current decade before today 

2299 :param after_today: include days in current decade after today 

2300 :example: Date('2012-04-04') 

2301 :return: Date 

2302 """ 

2303 today = dtdate.today() 

2304 this_decade_start = dtdate(today.year - (today.year % 10), 1, 1) 

2305 next_decade_start = dtdate(this_decade_start.year + 10, 1, 1) 

2306 

2307 if before_today and after_today: 

2308 return self.date_between_dates(this_decade_start, next_decade_start) 

2309 elif not before_today and after_today: 

2310 return self.date_between_dates(today, next_decade_start) 

2311 elif not after_today and before_today: 

2312 return self.date_between_dates(this_decade_start, today) 

2313 else: 

2314 return today 

2315 

2316 def date_this_year(self, before_today: bool = True, after_today: bool = False) -> dtdate: 

2317 """ 

2318 Gets a Date object for the current year. 

2319 

2320 :param before_today: include days in current year before today 

2321 :param after_today: include days in current year after today 

2322 :example: Date('2012-04-04') 

2323 :return: Date 

2324 """ 

2325 today = dtdate.today() 

2326 this_year_start = today.replace(month=1, day=1) 

2327 next_year_start = dtdate(today.year + 1, 1, 1) 

2328 

2329 if before_today and after_today: 

2330 return self.date_between_dates(this_year_start, next_year_start) 

2331 elif not before_today and after_today: 

2332 return self.date_between_dates(today, next_year_start) 

2333 elif not after_today and before_today: 

2334 return self.date_between_dates(this_year_start, today) 

2335 else: 

2336 return today 

2337 

2338 def date_this_month(self, before_today: bool = True, after_today: bool = False) -> dtdate: 

2339 """ 

2340 Gets a Date object for the current month. 

2341 

2342 :param before_today: include days in current month before today 

2343 :param after_today: include days in current month after today 

2344 :example: dtdate('2012-04-04') 

2345 :return: dtdate 

2346 """ 

2347 today = dtdate.today() 

2348 this_month_start = today.replace(day=1) 

2349 

2350 next_month_start = this_month_start + relativedelta.relativedelta(months=1) 

2351 if before_today and after_today: 

2352 return self.date_between_dates(this_month_start, next_month_start) 

2353 elif not before_today and after_today: 

2354 return self.date_between_dates(today, next_month_start) 

2355 elif not after_today and before_today: 

2356 return self.date_between_dates(this_month_start, today) 

2357 else: 

2358 return today 

2359 

2360 def time_series( 

2361 self, 

2362 start_date: DateParseType = "-30d", 

2363 end_date: DateParseType = "now", 

2364 precision: Optional[float] = None, 

2365 distrib: Optional[Callable[[datetime], float]] = None, 

2366 tzinfo: Optional[TzInfo] = None, 

2367 ) -> Iterator[Tuple[datetime, Any]]: 

2368 """ 

2369 Returns a generator yielding tuples of ``(<datetime>, <value>)``. 

2370 

2371 The data points will start at ``start_date``, and be at every time interval specified by 

2372 ``precision``. 

2373 ``distrib`` is a callable that accepts ``<datetime>`` and returns ``<value>`` 

2374 

2375 """ 

2376 start_date_ = self._parse_date_time(start_date, tzinfo=tzinfo) 

2377 end_date_ = self._parse_date_time(end_date, tzinfo=tzinfo) 

2378 

2379 if end_date_ < start_date_: 

2380 raise ValueError("`end_date` must be greater than `start_date`.") 

2381 

2382 precision_ = self._parse_timedelta((end_date_ - start_date_) / 30 if precision is None else precision) 

2383 if distrib is None: 

2384 

2385 def distrib(dt): 

2386 return self.generator.random.uniform(0, precision_) # noqa 

2387 

2388 if not callable(distrib): 

2389 raise ValueError(f"`distrib` must be a callable. Got {distrib} instead.") 

2390 

2391 datapoint: Union[float, int] = start_date_ 

2392 while datapoint < end_date_: 

2393 dt = timestamp_to_datetime(datapoint, tzinfo) 

2394 datapoint += precision_ 

2395 yield (dt, distrib(dt)) 

2396 

2397 def am_pm(self) -> str: 

2398 return self.date("%p") 

2399 

2400 def day_of_month(self) -> str: 

2401 return self.date("%d") 

2402 

2403 def day_of_week(self) -> str: 

2404 return self.date("%A") 

2405 

2406 def month(self) -> str: 

2407 return self.date("%m") 

2408 

2409 def month_name(self) -> str: 

2410 return self.date("%B") 

2411 

2412 def year(self) -> str: 

2413 return self.date("%Y") 

2414 

2415 def century(self) -> str: 

2416 """ 

2417 :example: 'XVII' 

2418 """ 

2419 return self.random_element(self.centuries) 

2420 

2421 def timezone(self) -> str: 

2422 return self.generator.random.choice(self.random_element(self.countries).timezones) # type: ignore 

2423 

2424 def pytimezone(self, *args: Any, **kwargs: Any) -> Optional[TzInfo]: 

2425 """ 

2426 Generate a random timezone (see `faker.timezone` for any args) 

2427 and return as a python object usable as a `tzinfo` to `datetime` 

2428 or other fakers. 

2429 

2430 :example: faker.pytimezone() 

2431 :return: dateutil.tz.tz.tzfile 

2432 """ 

2433 return gettz(self.timezone(*args, **kwargs)) # type: ignore 

2434 

2435 def date_of_birth( 

2436 self, 

2437 tzinfo: Optional[TzInfo] = None, 

2438 minimum_age: int = 0, 

2439 maximum_age: int = 115, 

2440 ) -> dtdate: 

2441 """ 

2442 Generate a random date of birth represented as a Date object, 

2443 constrained by optional miminimum_age and maximum_age 

2444 parameters. 

2445 

2446 :param tzinfo: Defaults to None. 

2447 :param minimum_age: Defaults to 0. 

2448 :param maximum_age: Defaults to 115. 

2449 

2450 :example: Date('1979-02-02') 

2451 :return: Date 

2452 """ 

2453 

2454 if not isinstance(minimum_age, int): 

2455 raise TypeError("minimum_age must be an integer.") 

2456 

2457 if not isinstance(maximum_age, int): 

2458 raise TypeError("maximum_age must be an integer.") 

2459 

2460 if maximum_age < 0: 

2461 raise ValueError("maximum_age must be greater than or equal to zero.") 

2462 

2463 if minimum_age < 0: 

2464 raise ValueError("minimum_age must be greater than or equal to zero.") 

2465 

2466 if minimum_age > maximum_age: 

2467 raise ValueError("minimum_age must be less than or equal to maximum_age.") 

2468 

2469 # In order to return the full range of possible dates of birth, add one 

2470 # year to the potential age cap and subtract one day if we land on the 

2471 # boundary. 

2472 

2473 now = datetime.now(tzinfo).date() 

2474 start_date = change_year(now, -(maximum_age + 1)) 

2475 end_date = change_year(now, -minimum_age) 

2476 

2477 dob = self.date_time_ad(tzinfo=tzinfo, start_datetime=start_date, end_datetime=end_date).date() 

2478 

2479 return dob if dob != start_date else dob + timedelta(days=1) 

2480 

2481 

2482def convert_timestamp_to_datetime(timestamp: Union[int, float], tzinfo: TzInfo) -> datetime: 

2483 import datetime as dt 

2484 

2485 if timestamp >= 0: 2485 ↛ 2488line 2485 didn't jump to line 2488, because the condition on line 2485 was never false

2486 return dt.datetime.fromtimestamp(timestamp, tzinfo) 

2487 else: 

2488 return dt.datetime(1970, 1, 1, tzinfo=tzinfo) + dt.timedelta(seconds=int(timestamp))