1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
3

X'ícGã'@sždZddlZddlZddlZddlmZmZmZmZddl	m
Z
ddlmZm
Z
mZddlmZmZdZedƒZeZeZeZd	d
„Zdd„Zd
d„Zdpdd„Zdqdd„Zdrdd„Zdsdd„ZGdd„dƒZddefdd„Zddefdd„Z ddefd d!„Z!ddefd"d#„Z"defd$d%„Z#d&efd'd(„Z$d&efd)d*„Z%d&efd+d,„Z&dd-ed.fd/d0„Z'ded.fd1d2„Z(dd-d.edd.fd3d4„Z)dd&efd5d6„Z*dd&defd7d8„Z+dd&defd9d:„Z,ddd;efd<d=„Z-d‚Z.dJdLd.d-efdMdN„Z/dOdP„Z0ddd;efdQdR„Z1ddefdSdT„Z2GdUdV„dVe3ƒZ4ed&fdWdX„Z5ed&fdYdZ„Z6Gd[d\„d\ƒZ7Gd]d^„d^ƒZ8dKd_d`dadbgddddKd_d`dadbgdKd_d`dadbgdKd_d`dadbgdKd_d`dadbgdKd_gdKgdKd_gdKd_d`gdKgddKd_d`dadbdcgdKd_d`dadbdcgdKd`dadbdcgdKd_d`dadbgdKd_d`dadbgdKd_d`dadbgdKd_gdKd_gdKd_gdKd_gdKd_gdKd_gdddKd_d`dagdKd_d`dadbgdKdagdKdagdKd_d`dagdKd_d`dadbgdKd_d`dadbgddœ#Z9deZ:iZ;dfdg„Z<dhdi„Z=djdk„Z>dldm„Z?dƒdndo„Z@dS)„aƒ
    babel.dates
    ~~~~~~~~~~~

    Locale dependent formatting and parsing of dates and times.

    The default locale for the functions in this module is determined by the
    following environment variables, in that order:

     * ``LC_TIME``,
     * ``LC_ALL``, and
     * ``LANG``

    :copyright: (c) 2013-2022 by the Babel Team.
    :license: BSD, see LICENSE for more details.
éN)ÚdateÚdatetimeÚtimeÚ	timedelta)Úbisect_right)Údefault_localeÚ
get_globalÚLocale)ÚUTCÚLOCALTZu	∅∅∅ÚLC_TIMEcCs€|dkrtjƒ}t}nbt|tƒr.d}t|ƒ}nJt|tƒrBd}t}n6t|ttfƒrpt	|ƒ}|j
dk	rj|j
}qxt}nd}|}||fS)z¦
    Parse a `dt_or_tzinfo` value into a datetime and a tzinfo.

    See the docs for this function's callers for semantics.

    :rtype: tuple[datetime, tzinfo]
    N)rÚnowrÚ
isinstanceÚstrÚget_timezoneÚintr
rÚ
_get_datetimeÚtzinfo)Údt_or_tzinfoÚdtr©rú,/tmp/pip-build-gk9425m9/babel/babel/dates.pyÚ_get_dt_and_tzinfo/s"



rcCsLt|ƒ\}}t|dƒr|jSt|dƒr6|jdk	r6|jS|j|pDtjƒƒSdS)z[
    Get the timezone name out of a time, datetime, or tzinfo object.

    :rtype: str
    ÚzoneÚkeyN)rÚhasattrrrÚtznamerÚutcnow)rrrrrrÚ_get_tz_nameLs
rcCsp|dkrtjƒSt|tƒs$t|tƒr.tj|ƒSt|tƒrHtjtj	ƒ|ƒSt|tƒrlt|t
ƒrltj|tƒƒS|S)aX
    Get a datetime out of an "instant" (date, time, datetime, number).

    .. warning:: The return values of this function may depend on the system clock.

    If the instant is None, the current moment is used.
    If the instant is a time, it's augmented with today's date.

    Dates are converted to naive datetimes with midnight as the time component.

    >>> _get_datetime(date(2015, 1, 1))
    datetime.datetime(2015, 1, 1, 0, 0)

    UNIX timestamps are converted to datetimes.

    >>> _get_datetime(1400000000)
    datetime.datetime(2014, 5, 13, 16, 53, 20)

    Other values are passed through as-is.

    >>> x = datetime(2015, 1, 1)
    >>> _get_datetime(x) is x
    True

    :param instant: date, time, datetime, integer, float or None
    :type instant: date|time|datetime|int|float|None
    :return: a datetime
    :rtype: datetime
    N)Ú	datetime_rrrÚfloatÚutcfromtimestamprÚcombinerÚtodayr)Úinstantrrrr[s

rcCsD|jdkr|jtd}|dk	r@|jt|ƒƒ}t|dƒr@|j|ƒ}|S)a+
    Ensure the datetime passed has an attached tzinfo.

    If the datetime is tz-naive to begin with, UTC is attached.

    If a tzinfo is passed in, the datetime is normalized to that timezone.

    >>> _ensure_datetime_tzinfo(datetime(2015, 1, 1)).tzinfo.zone
    'UTC'

    >>> tz = get_timezone("Europe/Stockholm")
    >>> _ensure_datetime_tzinfo(datetime(2015, 1, 1, 13, 15, tzinfo=UTC), tzinfo=tz).hour
    14

    :param datetime: Datetime to augment.
    :param tzinfo: Optional tznfo.
    :return: datetime with tzinfo
    :rtype: datetime
    N)rÚ	normalize)rÚreplacer
Ú
astimezonerrr%)rrrrrÚ_ensure_datetime_tzinfo…s


r(cCs’|dkrtjƒ}nt|ttfƒr*tj|ƒ}|jdkr@|jtd}t|tƒrz|dk	rp|j	|ƒ}t
|dƒrp|j|ƒ}|jƒ}n|dk	rŽ|j|d}|S)zÃ
    Get a timezoned time from a given instant.

    .. warning:: The return values of this function may depend on the system clock.

    :param time: time, datetime or None
    :rtype: time
    N)rr%)
rrrrr r!rr&r
r'rr%Útimetz)rrrrrÚ	_get_time¢s	







r*cCsL|dkrtSt|tƒs|Sy
tj|ƒStjk
rFtd|ƒ‚YnXdS)aéLooks up a timezone by name and returns it.  The timezone object
    returned comes from ``pytz`` and corresponds to the `tzinfo` interface and
    can be used with all of the functions of Babel that operate with dates.

    If a timezone is not known a :exc:`LookupError` is raised.  If `zone`
    is ``None`` a local zone object is returned.

    :param zone: the name of the timezone to look up.  If a timezone object
                 itself is passed in, mit's returned unchanged.
    NzUnknown timezone %s)rrrÚ_pytzÚtimezoneZUnknownTimeZoneErrorÚLookupError)rrrrr¼s

rcCsªtjdtdt|ƒ}t|ƒjdd}t|dƒs8tdƒ‚yBtdt	|j
|ƒƒ}|j|d}|j|}|j|}|j|}Wnt
tfk
r’dSXt|j
||||d	S)
a¼Given a timezone it will return a :class:`TimezoneTransition` object
    that holds the information about the next timezone transition that's going
    to happen.  For instance this can be used to detect when the next DST
    change is going to happen and how it looks like.

    The transition is calculated relative to the given datetime object.  The
    next transition that follows the date is used.  If a transition cannot
    be found the return value will be `None`.

    Transition information can only be provided for timezones returned by
    the :func:`get_timezone` function.

    This function is pending deprecation with no replacement planned in the
    Babel library.

    :param zone: the timezone for which the transition should be looked up.
                 If not provided the local timezone is used.
    :param dt: the date after which the next transition should be found.
               If not given the current time is assumed.
    zªget_next_timezone_transition() is deprecated and will be removed in the next version of Babel. Please see https://github.com/python-babel/babel/issues/716 for discussion.)ÚcategoryN)rÚ_utc_transition_timeszœGiven timezone does not have UTC transition times.  This can happen because the operating system fallback local timezone is used or a custom timezone objectré)Ú	activatesÚfrom_tzinfoÚ	to_tzinfoÚreference_date)ÚwarningsÚwarnÚDeprecationWarningrrr&rÚ	TypeErrorÚmaxrr/Z_transition_infoZ_tzinfosr-Ú
ValueErrorÚTimezoneTransition)rrÚidxZ	old_transZ	new_transZold_tzZnew_tzrrrÚget_next_timezone_transitionÑs(


r=c@sReZdZdZddd„Zedd„ƒZedd„ƒZed	d
„ƒZedd„ƒZ	d
d„Z
dS)r;aLA helper object that represents the return value from
    :func:`get_next_timezone_transition`.

    This class is pending deprecation with no replacement planned in the
    Babel library.

    :field activates:
        The time of the activation of the timezone transition in UTC.
    :field from_tzinfo:
        The timezone from where the transition starts.
    :field to_tzinfo:
        The timezone for after the transition.
    :field reference_date:
        The reference date that was provided.  This is the `dt` parameter
        to the :func:`get_next_timezone_transition`.
    NcCs*tjdtd||_||_||_||_dS)NzžTimezoneTransition is deprecated and will be removed in the next version of Babel. Please see https://github.com/python-babel/babel/issues/716 for discussion.)r.)r5r6r7r1r2r3r4)Úselfr1r2r3r4rrrÚ__init__szTimezoneTransition.__init__cCs|jjS)z/The name of the timezone before the transition.)r2Ú_tzname)r>rrrÚfrom_tz&szTimezoneTransition.from_tzcCs|jjS)z.The name of the timezone after the transition.)r3r@)r>rrrÚto_tz+szTimezoneTransition.to_tzcCst|jjjƒƒS)z0The UTC offset in seconds before the transition.)rr2Ú
_utcoffsetÚ
total_seconds)r>rrrÚfrom_offset0szTimezoneTransition.from_offsetcCst|jjjƒƒS)z/The UTC offset in seconds after the transition.)rr3rCrD)r>rrrÚ	to_offset5szTimezoneTransition.to_offsetcCsd|j|j|jfS)Nz"<TimezoneTransition %s -> %s (%s)>)rArBr1)r>rrrÚ__repr__:szTimezoneTransition.__repr__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r?ÚpropertyrArBrErFrGrrrrr;s

r;Úwidezstand-alonecCstj|ƒj||S)aGReturn the names for day periods (AM/PM) used by the locale.

    >>> get_period_names(locale='en_US')['am']
    u'AM'

    :param width: the width to use, one of "abbreviated", "narrow", or "wide"
    :param context: the context, either "format" or "stand-alone"
    :param locale: the `Locale` object, or a locale string
    )r	ÚparseZday_periods)ÚwidthÚcontextÚlocalerrrÚget_period_namesBs
rRÚformatcCstj|ƒj||S)a*Return the day names used by the locale for the specified format.

    >>> get_day_names('wide', locale='en_US')[1]
    u'Tuesday'
    >>> get_day_names('short', locale='en_US')[1]
    u'Tu'
    >>> get_day_names('abbreviated', locale='es')[1]
    u'mar'
    >>> get_day_names('narrow', context='stand-alone', locale='de_DE')[1]
    u'D'

    :param width: the width to use, one of "wide", "abbreviated", "short" or "narrow"
    :param context: the context, either "format" or "stand-alone"
    :param locale: the `Locale` object, or a locale string
    )r	rNÚdays)rOrPrQrrrÚ
get_day_namesOsrUcCstj|ƒj||S)aîReturn the month names used by the locale for the specified format.

    >>> get_month_names('wide', locale='en_US')[1]
    u'January'
    >>> get_month_names('abbreviated', locale='es')[1]
    u'ene'
    >>> get_month_names('narrow', context='stand-alone', locale='de_DE')[1]
    u'J'

    :param width: the width to use, one of "wide", "abbreviated", or "narrow"
    :param context: the context, either "format" or "stand-alone"
    :param locale: the `Locale` object, or a locale string
    )r	rNÚmonths)rOrPrQrrrÚget_month_namesbsrWcCstj|ƒj||S)aåReturn the quarter names used by the locale for the specified format.

    >>> get_quarter_names('wide', locale='en_US')[1]
    u'1st quarter'
    >>> get_quarter_names('abbreviated', locale='de_DE')[1]
    u'Q1'
    >>> get_quarter_names('narrow', locale='de_DE')[1]
    u'1'

    :param width: the width to use, one of "wide", "abbreviated", or "narrow"
    :param context: the context, either "format" or "stand-alone"
    :param locale: the `Locale` object, or a locale string
    )r	rNZquarters)rOrPrQrrrÚget_quarter_namesssrXcCstj|ƒj|S)a\Return the era names used by the locale for the specified format.

    >>> get_era_names('wide', locale='en_US')[1]
    u'Anno Domini'
    >>> get_era_names('abbreviated', locale='de_DE')[1]
    u'n. Chr.'

    :param width: the width to use, either "wide", "abbreviated", or "narrow"
    :param locale: the `Locale` object, or a locale string
    )r	rNZeras)rOrQrrrÚ
get_era_names„srYÚmediumcCstj|ƒj|S)ažReturn the date formatting patterns used by the locale for the specified
    format.

    >>> get_date_format(locale='en_US')
    <DateTimePattern u'MMM d, y'>
    >>> get_date_format('full', locale='de_DE')
    <DateTimePattern u'EEEE, d. MMMM y'>

    :param format: the format to use, one of "full", "long", "medium", or
                   "short"
    :param locale: the `Locale` object, or a locale string
    )r	rNZdate_formats)rSrQrrrÚget_date_format’s
r[cCs tj|ƒj}||krd}||S)a;Return the datetime formatting patterns used by the locale for the
    specified format.

    >>> get_datetime_format(locale='en_US')
    u'{1}, {0}'

    :param format: the format to use, one of "full", "long", "medium", or
                   "short"
    :param locale: the `Locale` object, or a locale string
    N)r	rNZdatetime_formats)rSrQÚpatternsrrrÚget_datetime_format¢sr]cCstj|ƒj|S)aReturn the time formatting patterns used by the locale for the specified
    format.

    >>> get_time_format(locale='en_US')
    <DateTimePattern u'h:mm:ss a'>
    >>> get_time_format('full', locale='de_DE')
    <DateTimePattern u'HH:mm:ss zzzz'>

    :param format: the format to use, one of "full", "long", "medium", or
                   "short"
    :param locale: the `Locale` object, or a locale string
    )r	rNZtime_formats)rSrQrrrÚget_time_format³s
r^ÚlongFcCsºtt|ƒƒ}tj|ƒ}|jj|ƒ}|jddd|j}t|dƒ\}}|r`|dkr`|dkr`dS|dkrx|dkrxd|S|dksˆ|dkrŽd	}n|d
krœd}n|j	dd}|||dfS)
açReturn the timezone associated with the given `datetime` object formatted
    as string indicating the offset from GMT.

    >>> dt = datetime(2007, 4, 1, 15, 30)
    >>> get_timezone_gmt(dt, locale='en')
    u'GMT+00:00'
    >>> get_timezone_gmt(dt, locale='en', return_z=True)
    'Z'
    >>> get_timezone_gmt(dt, locale='en', width='iso8601_short')
    u'+00'
    >>> tz = get_timezone('America/Los_Angeles')
    >>> dt = tz.localize(datetime(2007, 4, 1, 15, 30))
    >>> get_timezone_gmt(dt, locale='en')
    u'GMT-07:00'
    >>> get_timezone_gmt(dt, 'short', locale='en')
    u'-0700'
    >>> get_timezone_gmt(dt, locale='en', width='iso8601_short')
    u'-07'

    The long format depends on the locale, for example in France the acronym
    UTC string is used instead of GMT:

    >>> get_timezone_gmt(dt, 'long', locale='fr_FR')
    u'UTC-07:00'

    .. versionadded:: 0.9

    :param datetime: the ``datetime`` object; if `None`, the current date and
                     time in UTC is used
    :param width: either "long" or "short" or "iso8601" or "iso8601_short"
    :param locale: the `Locale` object, or a locale string
    :param return_z: True or False; Function returns indicator "Z"
                     when local time offset is 0
    éé<irÚZÚ
iso8601_shortz%+03dÚshortz	%+03d%02dÚiso8601z
%+03d:%02dZgmt)
r(rr	rNrÚ	utcoffsetrTÚsecondsÚdivmodÚzone_formats)rrOrQÚreturn_zÚoffsetrgÚhoursÚpatternrrrÚget_timezone_gmtÃs#
rncCstj|ƒ}t|ƒ}tdƒj||ƒ}|jj|iƒ}|jd}tdƒj|ƒ}||jkrVd}|j|}|rŠ|rŠttdƒj|gƒƒdkrŠ||S|jd}d|kr¦|d}	n\td	ƒj|ƒ}
|j	j|
iƒ}d|krÔ|d}	n.d
|krö|j
d
dƒdjddƒ}	n|jddƒ}	|r|	S|||	|d
œS)uVReturn a representation of the given timezone using "location format".

    The result depends on both the local display name of the country and the
    city associated with the time zone:

    >>> tz = get_timezone('America/St_Johns')
    >>> print(get_timezone_location(tz, locale='de_DE'))
    Kanada (St. John’s) Zeit
    >>> print(get_timezone_location(tz, locale='en'))
    Canada (St. John’s) Time
    >>> print(get_timezone_location(tz, locale='en', return_city=True))
    St. John’s
    >>> tz = get_timezone('America/Mexico_City')
    >>> get_timezone_location(tz, locale='de_DE')
    u'Mexiko (Mexiko-Stadt) Zeit'

    If the timezone is associated with a country that uses only a single
    timezone, just the localized country name is returned:

    >>> tz = get_timezone('Europe/Berlin')
    >>> get_timezone_name(tz, locale='de_DE')
    u'Mitteleurop\xe4ische Zeit'

    .. versionadded:: 0.9

    :param dt_or_tzinfo: the ``datetime`` or ``tzinfo`` object that determines
                         the timezone; if `None`, the current date and time in
                         UTC is assumed
    :param locale: the `Locale` object, or a locale string
    :param return_city: True or False, if True then return exemplar city (location)
                        for the time zone
    :return: the localized timezone name using location format

    Úzone_aliasesZregionZzone_territoriesZZZZterritory_zonesr0ÚfallbackZcityÚ
meta_zonesú/Ú_ú )Ú0Ú1)r	rNrrÚgetÚ
time_zonesriZterritoriesÚlenrqÚsplitr&)rrQÚreturn_cityrÚinfoZ
region_formatÚ	territoryZterritory_nameZfallback_formatZ	city_nameÚmetazoneÚ
metazone_inforrrÚget_timezone_locationùs4#



"


r€cCs0t|ƒ\}}tj|ƒ}t|ƒ}|dkrN|dkr4d}q^|j|ƒ}	|	rHd}q^d}n|dkr^tdƒ‚tdƒj||ƒ}|rv|S|jj|iƒ}
||
kr¤||
|kr¤|
||Stdƒj|ƒ}|r|j	j|iƒ}||kr||j|ƒ}
|dkoì|
t
kr|jd	iƒj|ƒ}
|
r|
S|dk	r$t|||d
St||dS)
aReturn the localized display name for the given timezone. The timezone
    may be specified using a ``datetime`` or `tzinfo` object.

    >>> dt = time(15, 30, tzinfo=get_timezone('America/Los_Angeles'))
    >>> get_timezone_name(dt, locale='en_US')
    u'Pacific Standard Time'
    >>> get_timezone_name(dt, locale='en_US', return_zone=True)
    'America/Los_Angeles'
    >>> get_timezone_name(dt, width='short', locale='en_US')
    u'PST'

    If this function gets passed only a `tzinfo` object and no concrete
    `datetime`,  the returned display name is indenpendent of daylight savings
    time. This can be used for example for selecting timezones, or to set the
    time of events that recur across DST changes:

    >>> tz = get_timezone('America/Los_Angeles')
    >>> get_timezone_name(tz, locale='en_US')
    u'Pacific Time'
    >>> get_timezone_name(tz, 'short', locale='en_US')
    u'PT'

    If no localized display name for the timezone is available, and the timezone
    is associated with a country that uses only a single timezone, the name of
    that country is returned, formatted according to the locale:

    >>> tz = get_timezone('Europe/Berlin')
    >>> get_timezone_name(tz, locale='de_DE')
    u'Mitteleurop\xe4ische Zeit'
    >>> get_timezone_name(tz, locale='pt_BR')
    u'Hor\xe1rio da Europa Central'

    On the other hand, if the country uses multiple timezones, the city is also
    included in the representation:

    >>> tz = get_timezone('America/St_Johns')
    >>> get_timezone_name(tz, locale='de_DE')
    u'Neufundland-Zeit'

    Note that short format is currently not supported for all timezones and
    all locales.  This is partially because not every timezone has a short
    code in every locale.  In that case it currently falls back to the long
    format.

    For more information see `LDML Appendix J: Time Zone Display Names
    <https://www.unicode.org/reports/tr35/#Time_Zone_Fallback>`_

    .. versionadded:: 0.9

    .. versionchanged:: 1.0
       Added `zone_variant` support.

    :param dt_or_tzinfo: the ``datetime`` or ``tzinfo`` object that determines
                         the timezone; if a ``tzinfo`` object is used, the
                         resulting display name will be generic, i.e.
                         independent of daylight savings time; if `None`, the
                         current date in UTC is assumed
    :param width: either "long" or "short"
    :param uncommon: deprecated and ignored
    :param zone_variant: defines the zone variation to return.  By default the
                           variation is defined from the datetime object
                           passed in.  If no datetime object is passed in, the
                           ``'generic'`` variation is assumed.  The following
                           values are valid: ``'generic'``, ``'daylight'`` and
                           ``'standard'``.
    :param locale: the `Locale` object, or a locale string
    :param return_zone: True or False. If true then function
                        returns long time zone ID
    NÚgenericÚdaylightÚstandardzInvalid zone variationrorqrdr_)rOrQ)rQ)rrƒr‚)
rr	rNrÚdstr:rrwrxrqÚNO_INHERITANCE_MARKERrnr€)rrOÚuncommonrQZzone_variantÚreturn_zonerrrr„r|r~rÚnamerrrÚget_timezone_nameEs>G



r‰cCsV|dkrtjƒ}nt|tƒr$|jƒ}tj|ƒ}|dkrBt||d}t|ƒ}|j	||ƒS)a¶Return a date formatted according to the given pattern.

    >>> d = date(2007, 4, 1)
    >>> format_date(d, locale='en_US')
    u'Apr 1, 2007'
    >>> format_date(d, format='full', locale='de_DE')
    u'Sonntag, 1. April 2007'

    If you don't want to use the locale default formats, you can specify a
    custom date pattern:

    >>> format_date(d, "EEE, MMM d, ''yy", locale='en')
    u"Sun, Apr 1, '07"

    :param date: the ``date`` or ``datetime`` object; if `None`, the current
                 date is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param locale: a `Locale` object or a locale identifier
    NÚfullr_rZrd)rQ)rŠr_rZrd)
Údate_r#rrrr	rNr[Ú
parse_patternÚapply)rrSrQrmrrrÚformat_date¼s


rŽcCsntt|ƒ|ƒ}tj|ƒ}|dkrZt||djddƒjdt||d	|d
ƒjdt|||dƒSt|ƒj	||ƒSd	S)
aReturn a date formatted according to the given pattern.

    >>> dt = datetime(2007, 4, 1, 15, 30)
    >>> format_datetime(dt, locale='en_US')
    u'Apr 1, 2007, 3:30:00 PM'

    For any pattern requiring the display of the time-zone, the third-party
    ``pytz`` package is needed to explicitly specify the time-zone:

    >>> format_datetime(dt, 'full', tzinfo=get_timezone('Europe/Paris'),
    ...                 locale='fr_FR')
    u'dimanche 1 avril 2007 \xe0 17:30:00 heure d\u2019\xe9t\xe9 d\u2019Europe centrale'
    >>> format_datetime(dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz",
    ...                 tzinfo=get_timezone('US/Eastern'), locale='en')
    u'2007.04.01 AD at 11:30:00 EDT'

    :param datetime: the `datetime` object; if `None`, the current date and
                     time is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param tzinfo: the timezone to apply to the time for display
    :param locale: a `Locale` object or a locale identifier
    rŠr_rZrd)rQú'Úz{0}N)rrQz{1})rŠr_rZrd)
r(rr	rNr]r&Úformat_timerŽrŒr)rrSrrQrrrÚformat_datetimeÝs


r’cCs8t||ƒ}tj|ƒ}|dkr(t||d}t|ƒj||ƒS)a@	Return a time formatted according to the given pattern.

    >>> t = time(15, 30)
    >>> format_time(t, locale='en_US')
    u'3:30:00 PM'
    >>> format_time(t, format='short', locale='de_DE')
    u'15:30'

    If you don't want to use the locale default formats, you can specify a
    custom time pattern:

    >>> format_time(t, "hh 'o''clock' a", locale='en')
    u"03 o'clock PM"

    For any pattern requiring the display of the time-zone a
    timezone has to be specified explicitly:

    >>> t = datetime(2007, 4, 1, 15, 30)
    >>> tzinfo = get_timezone('Europe/Paris')
    >>> t = tzinfo.localize(t)
    >>> format_time(t, format='full', tzinfo=tzinfo, locale='fr_FR')
    u'15:30:00 heure d\u2019\xe9t\xe9 d\u2019Europe centrale'
    >>> format_time(t, "hh 'o''clock' a, zzzz", tzinfo=get_timezone('US/Eastern'),
    ...             locale='en')
    u"09 o'clock AM, Eastern Daylight Time"

    As that example shows, when this function gets passed a
    ``datetime.datetime`` value, the actual time in the formatted string is
    adjusted to the timezone specified by the `tzinfo` parameter. If the
    ``datetime`` is "naive" (i.e. it has no associated timezone information),
    it is assumed to be in UTC.

    These timezone calculations are **not** performed if the value is of type
    ``datetime.time``, as without date information there's no way to determine
    what a given time would translate to in a different timezone without
    information about whether daylight savings time is in effect or not. This
    means that time values are left as-is, and the value of the `tzinfo`
    parameter is only used to display the timezone name if needed:

    >>> t = time(15, 30)
    >>> format_time(t, format='full', tzinfo=get_timezone('Europe/Paris'),
    ...             locale='fr_FR')
    u'15:30:00 heure normale d\u2019Europe centrale'
    >>> format_time(t, format='full', tzinfo=get_timezone('US/Eastern'),
    ...             locale='en_US')
    u'3:30:00 PM Eastern Standard Time'

    :param time: the ``time`` or ``datetime`` object; if `None`, the current
                 time in UTC is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param tzinfo: the time-zone to apply to the time for display
    :param locale: a `Locale` object or a locale identifier
    rŠr_rZrd)rQ)rŠr_rZrd)r*r	rNr^rŒr)rrSrrQrrrr‘s
7

r‘TcCs<tj|ƒ}|r$||jkr$t||jƒ}|j|}t||||ƒS)a‚Return a time and/or date formatted according to the given pattern.

    The skeletons are defined in the CLDR data and provide more flexibility
    than the simple short/long/medium formats, but are a bit harder to use.
    The are defined using the date/time symbols without order or punctuation
    and map to a suitable format for the given locale.

    >>> t = datetime(2007, 4, 1, 15, 30)
    >>> format_skeleton('MMMEd', t, locale='fr')
    u'dim. 1 avr.'
    >>> format_skeleton('MMMEd', t, locale='en')
    u'Sun, Apr 1'
    >>> format_skeleton('yMMd', t, locale='fi')  # yMMd is not in the Finnish locale; yMd gets used
    u'1.4.2007'
    >>> format_skeleton('yMMd', t, fuzzy=False, locale='fi')  # yMMd is not in the Finnish locale, an error is thrown
    Traceback (most recent call last):
        ...
    KeyError: yMMd

    After the skeleton is resolved to a pattern `format_datetime` is called so
    all timezone processing etc is the same as for that.

    :param skeleton: A date time skeleton as defined in the cldr data.
    :param datetime: the ``time`` or ``datetime`` object; if `None`, the current
                 time in UTC is used
    :param tzinfo: the time-zone to apply to the time for display
    :param fuzzy: If the skeleton is not found, allow choosing a skeleton that's
                  close enough to it.
    :param locale: a `Locale` object or a locale identifier
    )r	rNÚdatetime_skeletonsÚmatch_skeletonr’)ÚskeletonrrÚfuzzyrQrSrrrÚformat_skeletonBs


r—Úyearér`imÚmonthéÚweekéÚdayÚhourÚminuteraÚsecondr0g333333ë?c
sˆdkrtdƒ‚ˆdkr*tjdtdd‰t|tƒrJt|jd|jƒ‰n|‰t	j
ˆƒ‰‡‡‡‡fd	d
„}x®tD]¦\}}tˆƒ|}	|	|ks”||krp||kr®|	dkr®t
d|	ƒ}	tt|	ƒƒ}	ˆj|	ƒ}
d
}x.||ƒD]"}|d
k	rÒ|j|
ƒpð|jdƒ}PqÒW|d
krdS|jdt|	ƒƒSqpWdS)aå	Return a time delta according to the rules of the given locale.

    >>> format_timedelta(timedelta(weeks=12), locale='en_US')
    u'3 months'
    >>> format_timedelta(timedelta(seconds=1), locale='es')
    u'1 segundo'

    The granularity parameter can be provided to alter the lowest unit
    presented, which defaults to a second.

    >>> format_timedelta(timedelta(hours=3), granularity='day',
    ...                  locale='en_US')
    u'1 day'

    The threshold parameter can be used to determine at which value the
    presentation switches to the next higher unit. A higher threshold factor
    means the presentation will switch later. For example:

    >>> format_timedelta(timedelta(hours=23), threshold=0.9, locale='en_US')
    u'1 day'
    >>> format_timedelta(timedelta(hours=23), threshold=1.1, locale='en_US')
    u'23 hours'

    In addition directional information can be provided that informs
    the user if the date is in the past or in the future:

    >>> format_timedelta(timedelta(hours=1), add_direction=True, locale='en')
    u'in 1 hour'
    >>> format_timedelta(timedelta(hours=-1), add_direction=True, locale='en')
    u'1 hour ago'

    The format parameter controls how compact or wide the presentation is:

    >>> format_timedelta(timedelta(hours=3), format='short', locale='en')
    u'3 hr'
    >>> format_timedelta(timedelta(hours=3), format='narrow', locale='en')
    u'3h'

    :param delta: a ``timedelta`` object representing the time difference to
                  format, or the delta in seconds as an `int` value
    :param granularity: determines the smallest unit that should be displayed,
                        the value can be one of "year", "month", "week", "day",
                        "hour", "minute" or "second"
    :param threshold: factor that determines at which point the presentation
                      switches to the next higher unit
    :param add_direction: if this flag is set to `True` the return value will
                          include directional information.  For instance a
                          positive timedelta will include the information about
                          it being in the future, a negative will be information
                          about the value being in the past.
    :param format: the format, can be "narrow", "short" or "long". (
                   "medium" is deprecated, currently converted to "long" to
                   maintain compatibility)
    :param locale: a `Locale` object or a locale identifier
    ÚnarrowrdrZr_z1Format must be one of "narrow", "short" or "long"zU"medium" value for format param of format_timedelta is deprecated. Use "long" instead)r.i€Qc3sVˆr0ˆjd|}ˆdkr&|dVn
|dVd|}ˆjdj|iƒjˆƒVdS)NZdate_fieldsrÚfutureZpastz	duration-Z
unit_patterns)Ú_datarw)Za_unitZunit_rel_patterns)Ú
add_directionrSrQrgrrÚ_iter_patternsºs
z(format_timedelta.<locals>._iter_patternsrr0NÚotherrz{0})r¢rdrZr_)r8r5r6r7rrrrTrgr	rNÚTIMEDELTA_UNITSÚabsr9ÚroundÚplural_formrwr&r)
ÚdeltaZgranularityÚ	thresholdr¥rSrQr¦ÚunitZ
secs_per_unitÚvaluer«rmr\r)r¥rSrQrgrÚformat_timedeltass6:





r°cs²ˆˆjkr‡‡‡fdd„}nXtdd„||fDƒƒr@‡fdd„}n4tdd„||fDƒƒrf‡‡fdd„}n‡‡fdd„}||ƒ}||ƒ}||kr”||ƒSˆjjdd	ƒjd
|ƒjd|ƒS)Ncstˆ|ˆˆdS)N)rQ)r—)r)rQr•rrrÚ<lambda>Úsz+_format_fallback_interval.<locals>.<lambda>css$|]}t|tƒot|tƒVqdS)N)rrr)Ú.0Údrrrú	<genexpr>Ûsz,_format_fallback_interval.<locals>.<genexpr>cst|ˆdS)N)rQ)rŽ)r)rQrrr±Üscss$|]}t|tƒot|tƒVqdS)N)rrr)r²r³rrrr´Ýscst|ˆˆdS)N)rrQ)r‘)r)rQrrrr±Þscst|ˆˆdS)N)rrQ)r’)r)rQrrrr±àsz{0}-{1}z{0}z{1})r“ÚallÚinterval_formatsrwr&)ÚstartÚendr•rrQrSZformatted_startZ
formatted_endr)rQr•rrÚ_format_fallback_intervalØs
r¹cstjˆƒ‰ˆj}||ks|rJ|r2|r2t||ƒ}nd}|sJt||||ˆƒS||}||krlt||||ˆdStt|ƒ|d}tt|ƒ|d}t|ˆd}t|ˆd}	xNt	D]F}
|
|krª|j
|
ƒ|	j
|
ƒkrªdj‡fdd„t||
||fƒDƒƒSqªWt||||ˆƒS)uÀ
    Format an interval between two instants according to the locale's rules.

    >>> format_interval(date(2016, 1, 15), date(2016, 1, 17), "yMd", locale="fi")
    u'15.–17.1.2016'

    >>> format_interval(time(12, 12), time(16, 16), "Hm", locale="en_GB")
    '12:12–16:16'

    >>> format_interval(time(5, 12), time(16, 16), "hm", locale="en_US")
    '5:12 AM – 4:16 PM'

    >>> format_interval(time(16, 18), time(16, 24), "Hm", locale="it")
    '16:18–16:24'

    If the start instant equals the end instant, the interval is formatted like the instant.

    >>> format_interval(time(16, 18), time(16, 18), "Hm", locale="it")
    '16:18'

    Unknown skeletons fall back to "default" formatting.

    >>> format_interval(date(2015, 1, 1), date(2017, 1, 1), "wzq", locale="ja")
    '2015/01/01~2017/01/01'

    >>> format_interval(time(16, 18), time(16, 24), "xxx", locale="ja")
    '16:18:00~16:24:00'

    >>> format_interval(date(2016, 1, 15), date(2016, 1, 17), "xxx", locale="de")
    '15.01.2016 – 17.01.2016'

    :param start: First instant (datetime/date/time)
    :param end: Second instant (datetime/date/time)
    :param skeleton: The "skeleton format" to use for formatting.
    :param tzinfo: tzinfo to use (if none is already attached)
    :param fuzzy: If the skeleton is not found, allow choosing a skeleton that's
                  close enough to it.
    :param locale: A locale object or identifier.
    :return: Formatted interval
    N)r–rQ)r)rQrc3s"|]\}}t|ƒj|ˆƒVqdS)N)rŒr)r²rmr$)rQrrr´Gsz"format_interval.<locals>.<genexpr>)
r	rNr¶r”r¹r—r(rÚDateTimeFormatÚPATTERN_CHAR_ORDERÚextractÚjoinÚzip)r·r¸r•rr–rQr¶Zskel_formatsZ	start_fmtZend_fmtÚfieldr)rQrÚformat_intervalïs,)
	

rÀcCsÂt||ƒ}t|jdd|jd|jƒ}tj|ƒ}|jj|iƒj	ƒ}x6|D].\}}x$|D]}d|kr\|d|kr\|Sq\WqNWx(|D]\}}x|D]}d|ko®d|kr*|d|dkrè|d|koÜ|dknræ|SnB|d|koþdkns&d|ko|dknr*|Sd}	}
d|krN||dkrNd}	d	|krj||d	krjd}
d|kr†||dkr†d}
d
|kr˜t
dƒ‚|	rš|
rš|SqšWqˆW|dkrºd
SdSdS)uW
    Get the day period ID for a given time.

    This ID can be used as a key for the period name dictionary.

    >>> get_period_names(locale="de")[get_period_id(time(7, 42), locale="de")]
    u'Morgen'

    >>> get_period_id(time(0), locale="en_US")
    u'midnight'

    >>> get_period_id(time(0), type="selection", locale="en_US")
    u'night1'

    :param time: The time to inspect.
    :param tzinfo: The timezone for the time. See ``format_time``.
    :param type: The period type to use. Either "selection" or None.
                 The selection type is used for selecting among phrases such as
                 “Your email arrived yesterday evening” or “Your email arrived last night”.
    :param locale: the `Locale` object, or a locale string
    :return: period ID. Something is always returned -- even if it's just "am" or "pm".
    raZatÚfromZbeforei€QrFTZtoÚafterz$'after' is deprecated as of CLDR 29.iÀ¨ÚamÚpmN)r*rrŸr r¡r	rNZday_period_rulesrwÚitemsÚNotImplementedError)rrÚtyperQZseconds_past_midnightZrulesetsZrule_idÚrulesZruleZstart_okZend_okrrrÚ
get_period_idQs>
"

  

rÉc@seZdZdS)Ú
ParseErrorN)rHrIrJrrrrrʗsrÊc
Cs6tjd|ƒ}|stdƒ‚tjd|tjd}|rVyttt|jƒƒŽSt	k
rTYnXt
||djjƒ}|j
dƒ}|j
dƒ}|dkrŽ|j
d	ƒ}|j
d
ƒ}|df|df|d
fg}	|	jƒdd„t|	ƒDƒ}	||	d}
t|
ƒdkrîdt|
ƒ}
nt|
ƒ}
t||	dƒ}t||	d
ƒ}|dkr*||}}t|
||ƒS)aØParse a date from a string.

    This function first tries to interpret the string as ISO-8601
    date format, then uses the date format for the locale as a hint to
    determine the order in which the date fields appear in the string.

    >>> parse_date('4/1/04', locale='en_US')
    datetime.date(2004, 4, 1)
    >>> parse_date('01.04.2004', locale='de_DE')
    datetime.date(2004, 4, 1)
    >>> parse_date('2004-04-01', locale='en_US')
    datetime.date(2004, 4, 1)
    >>> parse_date('2004-04-01', locale='de_DE')
    datetime.date(2004, 4, 1)

    :param string: the string containing the date
    :param locale: a `Locale` object or a locale identifier
    :param format: the format to use (see ``get_date_format``)
    z(\d+)zNo numbers were found in inputz^(\d{4})-?([01]\d)-?([0-3]\d)$)Úflags)rSrQÚyÚmrÚlr³ÚYÚMÚDcSsi|]\}}||d“qS)r0r)r²r<Úitemrrrú
<dictcomp>Æszparse_date.<locals>.<dictcomp>éiÐé)ÚreÚfindallrÊÚmatchÚASCIIrÚmaprÚgroupsr:r[rmÚlowerÚindexÚsortÚ	enumeratery)
ÚstringrQrSÚnumbersZ	iso_alikeÚ
format_strZyear_idxZ	month_idxZday_idxÚindexesr˜ršržrrrÚ
parse_date›s8





räc
Cstjd|ƒ}|stdƒ‚t||djjƒ}|jdƒ}|dkrF|jdƒ}|jdƒ}|jdƒ}|d	f|d
f|dfg}|jƒdd
„t|ƒDƒ}d}	d|kr¦d|jƒkr¦d}	d}
}t	||d	ƒ|	}t
|ƒdkrút	||d
ƒ}
t
|ƒdkrút	||dƒ}t||
|ƒS)aÓParse a time from a string.

    This function uses the time format for the locale as a hint to determine
    the order in which the time fields appear in the string.

    >>> parse_time('15:30:00', locale='en_US')
    datetime.time(15, 30)

    :param string: the string containing the time
    :param locale: a `Locale` object or a locale identifier
    :param format: the format to use (see ``get_time_format``)
    :return: the parsed time
    :rtype: `time`
    z(\d+)zNo numbers were found in input)rSrQÚhrÚkrÍÚsÚHrÐÚScSsi|]\}}||d“qS)r0r)r²r<rÒrrrrÓôszparse_time.<locals>.<dictcomp>ÚarÄrÕr0rÔ)rÖr×rÊr^rmrÜrÝrÞrßrryr)
ràrQrSrárâZhour_idxÚmin_idxZsec_idxrãZhour_offsetr r¡rŸrrrÚ
parse_time×s.



rìc@s4eZdZdd„Zdd„Zdd„Zdd„Zd	d
„ZdS)ÚDateTimePatterncCs||_||_dS)N)rmrS)r>rmrSrrrr?szDateTimePattern.__init__cCsdt|ƒj|jfS)Nz<%s %r>)rÇrHrm)r>rrrrGszDateTimePattern.__repr__cCs
|j}|S)N)rm)r>ÚpatrrrÚ__str__szDateTimePattern.__str__cCst|ƒtk	rtS|j|S)N)rÇrºÚNotImplementedrS)r>r§rrrÚ__mod__szDateTimePattern.__mod__cCs|t||ƒS)N)rº)r>rrQrrrrszDateTimePattern.applyN)rHrIrJr?rGrïrñrrrrrrí	s
ríc@s¢eZdZdd„Zdd„Zdd„Zdd„Zd	d
„Zdd„Zd
d„Z	dd„Z
d(dd„Zdd„Zdd„Z
dd„Zdd„Zdd„Zdd „Zd!d"„Zd)d$d%„Zd*d&d'„Zd#S)+rºcCsNt|tttfƒst‚t|ttfƒr8|jdkr8|jtd}||_t	j
|ƒ|_dS)N)r)rrrrÚAssertionErrorrr&r
r¯r	rNrQ)r>r¯rQrrrr?!s
zDateTimeFormat.__init__cCs|d}t|ƒ}|dkr$|j||ƒS|d'kr8|j||ƒS|d(krL|j||ƒS|d)kr`|j||ƒS|d*krt|j||ƒS|dkrŒ|j|jj|ƒS|d
krž|j	|ƒS|dkr®|j
ƒS|d+krÂ|j||ƒS|d,krØ|j||ƒS|dkr|jj
ddkr|jd|ƒS|j|jj
d|ƒSnì|dkr2|j|jj
|ƒS|dkrP|j|jj
d|ƒS|dkr†|jj
dkrt|jd|ƒS|j|jj
|ƒSn~|dkr |j|jj|ƒS|dkrº|j|jj|ƒS|dkrÎ|j|ƒS|dkrâ|j|ƒS|d-krø|j||ƒStd&|ƒ‚dS).NrÚGrÌrÏÚuÚQÚqrÐÚLÚwÚWr³rÑÚFÚEÚeÚcrêÚbÚBrårÕrèÚKrær`rÍrçréÚAÚzrbÚvÚVÚxÚXÚOzUnsupported date/time field %r)rÌrÏrô)rõrö)rÐr÷)rørù)rûrürý)rêrþrÿ)rrbrrrrr)ryÚ
format_eraÚformat_yearÚformat_quarterÚformat_monthÚformat_weekrSr¯ržÚformat_day_of_yearÚformat_day_of_week_in_monthÚformat_weekdayÚ
format_periodrŸr r¡Úformat_frac_secondsÚformat_milliseconds_in_dayÚformat_timezoneÚKeyError)r>rˆÚcharÚnumrrrÚ__getitem__(sZ












zDateTimeFormat.__getitem__cCs¢t|ƒd}|dkr|jjS|dkr,|jjS|dkr<|jjS|dkrL|jjS|dkrd|jjdpbdS|dkrt|jjS|d	krŒt|jjdkƒStd
||jfƒ‚dS)NrrÌrÐr³rèrårÕrÍrêz&Not implemented: extracting %r from %r)	rr¯r˜ršržrŸr rrÆ)r>rrrrr¼Zs zDateTimeFormat.extractcCs6ddddœtd|ƒ}t|jjdkƒ}t||jƒ|S)NÚabbreviatedrMr¢)ééérr)r9rr¯r˜rYrQ)r>rrrOZerarrrrmszDateTimeFormat.format_eracCsB|jj}|jƒr|jjƒd}|j||ƒ}|dkr>|dd…}|S)NrrÔéþÿÿÿ)r¯r˜ÚisupperÚisocalendarrS)r>rrr¯r˜rrrr	rszDateTimeFormat.format_yearcCsX|jjddd}|dkr(d||fSddddœ|}d	d
dœ|}t|||jƒ|S)Nr0rrÔz%0*drrMr¢)rrrrSzstand-alone)rõrö)r¯ršrXrQ)r>rrZquarterrOrPrrrr
{szDateTimeFormat.format_quartercCsL|dkrd||jjfSddddœ|}ddd	œ|}t|||jƒ|jjS)
NrÔz%0*drrMr¢)rrrrSzstand-alone)rÐr÷)r¯ršrWrQ)r>rrrOrPrrrrƒs
zDateTimeFormat.format_monthcCsœ|jƒrT|jƒ}|j|ƒ}|dkrH|jt|d}|j|j|ƒ|jƒƒ}|j||ƒS|j|jjƒ}|dkr|jt|jjd}|j|j|jƒƒ}d|SdS)Nr)rTz%d)ÚislowerÚget_day_of_yearÚget_week_numberr¯rÚweekdayrSrž)r>rrZday_of_yearrœrrrrrŠs

zDateTimeFormat.format_weekrûrcCs~|dkr>|jƒr:d|jj|jjƒ}|j|dd|ƒSd}|jjƒ}dddddœ|}|d	krhd
}nd}t|||jƒ|S)ai
        Return weekday from parsed datetime according to format pattern.

        >>> format = DateTimeFormat(date(2016, 2, 28), Locale.parse('en_US'))
        >>> format.format_weekday()
        u'Sunday'

        'E': Day of week - Use one through three letters for the abbreviated day name, four for the full (wide) name,
             five for the narrow name, or six for the short name.
        >>> format.format_weekday('E',2)
        u'Sun'

        'e': Local day of week. Same as E except adds a numeric value that will depend on the local starting day of the
             week, using one or two letters. For this example, Monday is the first day of the week.
        >>> format.format_weekday('e',2)
        '01'

        'c': Stand-Alone local day of week - Use one letter for the local numeric value (same as 'e'), three for the
             abbreviated day name, four for the full (wide) name, five for the narrow name, or six for the short name.
        >>> format.format_weekday('c',1)
        '1'

        :param char: pattern format character ('e','E','c')
        :param num: count of format character

        rrr0rrMr¢rd)rrrérýzstand-alonerS)rrQÚfirst_week_dayr¯r"rSrU)r>rrr¯r"rOrPrrrršs
zDateTimeFormat.format_weekdaycCs|j|jƒ|ƒS)N)rSr )r>rrrrr
Âsz!DateTimeFormat.format_day_of_yearcCsd|jjdddS)Nz%dr0r)r¯rž)r>rrrrÅsz*DateTimeFormat.format_day_of_week_in_monthcCs¤ddddœtd|ƒdddg}|dkr@|jjdkr6dnd	}d
}n t|j|jd}|dkr\d
nd
}x,|D]$}t|||jd}||krf||SqfWtd||jfƒ‚dS)u)
        Return period from parsed datetime according to format pattern.

        >>> format = DateTimeFormat(time(13, 42), 'fi_FI')
        >>> format.format_period('a', 1)
        u'ip.'
        >>> format.format_period('b', 1)
        u'iltap.'
        >>> format.format_period('b', 4)
        u'iltapäivä'
        >>> format.format_period('B', 4)
        u'iltapäivällä'
        >>> format.format_period('B', 5)
        u'ip.'

        >>> format = DateTimeFormat(datetime(2022, 4, 28, 6, 27), 'zh_Hant')
        >>> format.format_period('a', 1)
        u'上午'
        >>> format.format_period('b', 1)
        u'清晨'
        >>> format.format_period('B', 1)
        u'清晨'

        :param char: pattern format character ('a', 'b', 'B')
        :param num: count of format character

        rrMr¢)rrrrrêrÕrÄrÃrS)rQrÿzstand-alone)rPrOrQz Could not format period %s in %sN)r9r¯rŸrÉrQrRr:)r>rrZwidthsZperiodrPrOZperiod_namesrrrrÈs

zDateTimeFormat.format_periodcCs&|jjd}|jt||ƒd||ƒS)zŽ Return fractional seconds.

        Rounds the time's microseconds to the precision given by the number         of digits passed in.
        i@Bé
)r¯ÚmicrosecondrSrª)r>rr¯rrrròsz"DateTimeFormat.format_frac_secondscCs<|jjd|jjd|jjd|jjd}|j||ƒS)Nièi`êi€î6)r¯r&r¡r rŸrS)r>rÚmsecsrrrrûs0z)DateTimeFormat.format_milliseconds_in_daycCsäddddœtd|ƒ}|dkr0t|j||jdS|dkrf|d	krTt|j||jd
dSt|j||jdS|dkrŒ|d
krˆt|j||jdSnT|dkr¨t|jj||jdS|dkr|dkrÐt|jj|d
|jdS|dkrìt|jj|jd
dS|dkr
t|jj|jd
dSt|jj|jdS|dkr‚|dkrDt|jd|jd
dS|dkrbt|jd|jd
dS|dkràt|jd|jd
dSn^|dkrà|dkr¨t|jd|jdS|dkrÄt|jd|jdS|dkràt|jd|jdSdS)Nrdr_re)rrrrr)rQrbrT)rQrjrrrrr0)r†rQrÔ)rQr‡)rQr{rrc)rOrQrjr)rOrQ)rÔr)rr)rÔr)rr)r9r‰r¯rQrnrr€)r>rrrOrrrrsN













zDateTimeFormat.format_timezonecCsd||fS)Nz%0*dr)r>r¯ÚlengthrrrrS+szDateTimeFormat.formatNcCs&|dkr|j}||jdddjdS)Nr0)ršrž)r¯r&rT)r>rrrrr .szDateTimeFormat.get_day_of_yearcCsœ|dkr|jjƒ}||jj|dd}|dkr:|d7}||dd}d||jjkrb|d7}|jjdkr˜t|jjdddjƒd}||kr˜||8}|S)a‚Return the number of the week of a day within a period. This may be
        the week number in a year or the week number in a month.

        Usually this will return a value equal to or greater than 1, but if the
        first week of the period is so short that it actually counts as the last
        week of the previous period, this function will return 0.

        >>> format = DateTimeFormat(date(2006, 1, 8), Locale.parse('de_DE'))
        >>> format.get_week_number(6)
        1

        >>> format = DateTimeFormat(date(2006, 1, 8), Locale.parse('en_US'))
        >>> format.get_week_number(6)
        2

        :param day_of_period: the number of the day in the period (usually
                              either the day of month or the day of year)
        :param day_of_week: the week day; if ommitted, the week day of the
                            current date is assumed
        Nr0rrérÕ)r˜ržrš)r¯r"rQr$Z
min_week_daysrr˜r)r>Z
day_of_periodZday_of_weekZ	first_dayZweek_numberZ	max_weeksrrrr!3s
zDateTimeFormat.get_week_number)rûr)N)N)rHrIrJr?rr¼rr	r
rrrr
rrrrrrSr r!rrrrrºs$2	
(*	+
rºrÔrrrr#)#rórÌrÏrôrõrörÐr÷rørùr³rÑrúÚgrûrürýrêrþrÿrårèrrærÍrçrérrrbrrrrrZ(GyYuUQqMLlwWdDFgEecabBChHKkjJmsSAzZOvVXxcCsÆt|ƒtkr|S|tkr t|Sg}x„t|ƒD]x\}}|dkrR|j|jddƒƒq.|dkrš|\}}t|}|r†||kr†td||ƒ‚|jd||ƒq.td|ƒ‚q.Wt|dj	|ƒƒt|<}|S)	aParse date, time, and datetime format patterns.

    >>> parse_pattern("MMMMd").format
    u'%(MMMM)s%(d)s'
    >>> parse_pattern("MMM d, yyyy").format
    u'%(MMM)s %(d)s, %(yyyy)s'

    Pattern can contain literal strings in single quotes:

    >>> parse_pattern("H:mm' Uhr 'z").format
    u'%(H)s:%(mm)s Uhr %(z)s'

    An actual single quote can be used by using two adjacent single quote
    characters:

    >>> parse_pattern("hh' o''clock'").format
    u"%(hh)s o'clock"

    :param pattern: the formatting pattern to parse
    Úcharsú%z%%r¿zInvalid length for field: %rz%%(%s)szUnknown token type: %sr)
rÇríÚ_pattern_cacheÚtokenize_patternÚappendr&Ú
PATTERN_CHARSr:rÆr½)rmÚresultÚtok_typeÚ	tok_valueÚ	fieldcharÚfieldnumÚlimitrîrrrrŒxs$rŒcs<g‰d}g‰dg‰dg‰‡‡fdd„}‡‡‡fdd„}xât|jdd	ƒƒD]Î\}}|dkrê|d
kr€ˆdrp|ƒn
ˆrz|ƒg}nh|tkrЈr’|ƒ|ˆdkr°ˆdd7<qèˆdr¾|ƒ|ˆd<dˆd<nˆdrÞ|ƒˆj|ƒqH|dk	rH|d
krˆj|ƒd}qH|j|ƒqHWˆdr,|ƒnˆr8|ƒˆS)ay
    Tokenize date format patterns.

    Returns a list of (token_type, token_value) tuples.

    ``token_type`` may be either "chars" or "field".

    For "chars" tokens, the value is the literal value.

    For "field" tokens, the value is a tuple of (field character, repetition count).

    :param pattern: Pattern string
    :type pattern: str
    :rtype: list[tuple]
    Nrrcs*ˆjddjˆƒjddƒfƒˆdd…=dS)Nr+rúr)r/r½r&r)Úcharbufr1rrÚappend_chars¼sz&tokenize_pattern.<locals>.append_charscs.ˆjdˆdˆdffƒdˆd<dˆd<dS)Nr¿rr)r/r)r4r5r1rrÚappend_fieldÀsz&tokenize_pattern.<locals>.append_fieldz''r7rr0)rßr&r0r/Úextend)rmZquotebufr9r:r<rr)r8r4r5r1rr.¦sJ



r.cCs|g}xl|D]d\}}|dkr2|j|d|dƒq
|dkr
tdd„|DƒƒsX|j|ƒq
|jd|jdd	ƒƒq
Wd
j|ƒS)z´
    Turn a date format pattern token stream back into a string.

    This is the reverse operation of ``tokenize_pattern``.

    :type tokens: Iterable[tuple]
    :rtype: str
    r¿rr0r+css|]}|tkVqdS)N)r0)r²Úchrrrr´ùsz%untokenize_pattern.<locals>.<genexpr>z'%s'rz''r)r/Úanyr&r½)ÚtokensÚoutputr2r3rrrÚuntokenize_patternës	r@cCsvtƒ}gg}xZt|ƒD]N\}}|dkrR|d|krD|jgƒ|jƒ|j|dƒ|dj||fƒqWdd„|DƒS)u
    Split an interval-describing datetime pattern into multiple pieces.

    > The pattern is then designed to be broken up into two pieces by determining the first repeating field.
    - https://www.unicode.org/reports/tr35/tr35-dates.html#intervalFormats

    >>> split_interval_pattern(u'E d.M. – E d.M.')
    [u'E d.M. – ', 'E d.M.']
    >>> split_interval_pattern("Y 'text' Y 'more text'")
    ["Y 'text '", "Y 'more text'"]
    >>> split_interval_pattern(u"E, MMM d – E")
    [u'E, MMM d – ', u'E']
    >>> split_interval_pattern("MMM d")
    ['MMM d']
    >>> split_interval_pattern("y G")
    ['y G']
    >>> split_interval_pattern(u"MMM d – d")
    [u'MMM d – ', u'd']

    :param pattern: Interval pattern string
    :return: list of "subpatterns"
    r¿rr0cSsg|]}t|ƒ‘qSr)r@)r²r>rrrú
<listcomp>#sz*split_interval_pattern.<locals>.<listcomp>éÿÿÿÿ)Úsetr.r/ÚclearÚadd)rmZseen_fieldsÚpartsr2r3rrrÚsplit_interval_patterns
rGcCsHtdd„|Dƒƒ}d|kr:tdd„|Dƒƒr:|jddƒ}tdd„t|ƒDƒƒj}d}d}xè|D]à}tdd„t|ƒDƒƒj}d	}x’tD]Š}	||	d	ƒ}
||	d	ƒ}|
|kr¨q†|d	ks¸|
d	krÌ|sÂd}P|d
7}q†|	dkoò|
dkrä|dksö|
dkoò|dkr|d
7}q†|t|
|ƒ7}q†W|sq`|s.||kr6|}|}|d	kr`Pq`W|S)a¦
    Find the closest match for the given datetime skeleton among the options given.

    This uses the rules outlined in the TR35 document.

    >>> match_skeleton('yMMd', ('yMd', 'yMMMd'))
    'yMd'

    >>> match_skeleton('yMMd', ('jyMMd',), allow_different_fields=True)
    'jyMMd'

    >>> match_skeleton('yMMd', ('qyMMd',), allow_different_fields=False)

    >>> match_skeleton('hmz', ('hmv',))
    'hmv'

    :param skeleton: The skeleton to match
    :type skeleton: str
    :param options: An iterable of other skeletons to match against
    :type options: Iterable[str]
    :return: The closest skeleton match, or if no match was found, None.
    :rtype: str|None
    css|]}|r|VqdS)Nr)r²Úoptionrrrr´Esz!match_skeleton.<locals>.<genexpr>rcss|]}d|kVqdS)rNr)r²rHrrrr´Gsrcss"|]}|ddkr|dVqdS)rr¿r0Nr)r²Útrrrr´JsNcss"|]}|ddkr|dVqdS)rr¿r0Nr)r²rIrrrr´NsrirÐrÔé)Úsortedr=r&Údictr.rwr0r©)r•ÚoptionsZallow_different_fieldsZget_input_field_widthZ
best_skeletonZ
best_distancerHZget_opt_field_widthZdistancer¿Zinput_widthÚ	opt_widthrrrr”&s<




*
r”)N)N)N)NNi€Qé€3á©r˜rOi€Qé'©ršrQi€Qé€:	©rœrSé€Q©ržrU©rŸr™©r ra©r¡r0)rPrRrTrVrWrXrY)F)ArKrÖr5Zpytzr+rrrrÚbisectrZ
babel.corerrr	Z
babel.utilr
rr…rr‹rZtime_rrrr(r*rr=r;rRrUrWrXrYr[r]r^rnr€r‰rŽr’r‘r—r¨r°r¹rÀrÉr:rÊrärìrírºr0r»r-rŒr.r@rGr”rrrrÚ<module>sš	*



6;
6Lv!%?'cbF<2D
($
"(.E&