Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numberToTimezone from "phone-number-to-timezone";
- import { DateTime } from "luxon";
- // console.log( numberToTimezone.getLocalInfo("16783616626"));
- const usStateToNumbers = {
- "Alabama": [
- 205,
- 251,
- 256,
- 334,
- 659,
- 938
- ],
- "Alaska": [
- 907
- ],
- "Arizona": [
- 480,
- 520,
- 602,
- 623,
- 928
- ],
- "Arkansas": [
- 327,
- 479,
- 501,
- 870
- ],
- "California": [
- 209,
- 213,
- 279,
- 310,
- 323,
- 341,
- 350,
- 369,
- 408,
- 415,
- 424,
- 442,
- 510,
- 530,
- 559,
- 562,
- 619,
- 626,
- 628,
- 650,
- 657,
- 661,
- 669,
- 707,
- 714,
- 738,
- 747,
- 760,
- 805,
- 818,
- 820,
- 831,
- 840,
- 858,
- 909,
- 916,
- 925,
- 949,
- 951
- ],
- "Colorado": [
- 303,
- 719,
- 720,
- 970,
- 983
- ],
- "Connecticut": [
- 203,
- 475,
- 860,
- 959
- ],
- "Delaware": [
- 302
- ],
- "Florida": [
- 239,
- 305,
- 321,
- 324,
- 352,
- 386,
- 407,
- 448,
- 561,
- 645,
- 656,
- 689,
- 727,
- 728,
- 754,
- 772,
- 786,
- 813,
- 850,
- 863,
- 904,
- 941,
- 954
- ],
- "Georgia": [
- 229,
- 404,
- 470,
- 478,
- 678,
- 706,
- 762,
- 770,
- 912,
- 943
- ],
- "Hawaii": [
- 808
- ],
- "Idaho": [
- 208,
- 986
- ],
- "Illinois": [
- 217,
- 224,
- 309,
- 312,
- 331,
- 447,
- 464,
- 618,
- 630,
- 708,
- 730,
- 773,
- 779,
- 815,
- 847,
- 861,
- 872
- ],
- "Indiana": [
- 219,
- 260,
- 317,
- 463,
- 574,
- 765,
- 812,
- 930
- ],
- "Iowa": [
- 319,
- 515,
- 563,
- 641,
- 712
- ],
- "Kansas": [
- 316,
- 620,
- 785,
- 913
- ],
- "Kentucky": [
- 270,
- 364,
- 502,
- 606,
- 859
- ],
- "Louisiana": [
- 225,
- 318,
- 337,
- 457,
- 504,
- 985
- ],
- "Maine": [
- 207
- ],
- "Maryland": [
- 227,
- 240,
- 301,
- 410,
- 443,
- 667
- ],
- "Massachusetts": [
- 339,
- 351,
- 413,
- 508,
- 617,
- 774,
- 781,
- 857,
- 978
- ],
- "Michigan": [
- 231,
- 248,
- 269,
- 313,
- 517,
- 586,
- 616,
- 679,
- 734,
- 810,
- 906,
- 947,
- 989
- ],
- "Minnesota": [
- 218,
- 320,
- 507,
- 612,
- 651,
- 763,
- 924,
- 952
- ],
- "Mississippi": [
- 228,
- 601,
- 662,
- 769
- ],
- "Missouri": [
- 235,
- 314,
- 417,
- 557,
- 573,
- 636,
- 660,
- 816,
- 975
- ],
- "Montana": [
- 406
- ],
- "Nebraska": [
- 308,
- 402,
- 531
- ],
- "Nevada": [
- 702,
- 725,
- 775
- ],
- "New Hampshire": [
- 603
- ],
- "New Jersey": [
- 201,
- 551,
- 609,
- 640,
- 732,
- 848,
- 856,
- 862,
- 908,
- 973
- ],
- "New Mexico": [
- 505,
- 575
- ],
- "New York": [
- 212,
- 315,
- 329,
- 332,
- 347,
- 363,
- 516,
- 518,
- 585,
- 607,
- 624,
- 631,
- 646,
- 680,
- 716,
- 718,
- 838,
- 845,
- 914,
- 917,
- 929,
- 934
- ],
- "North Carolina": [
- 252,
- 336,
- 472,
- 704,
- 743,
- 828,
- 910,
- 919,
- 980,
- 984
- ],
- "North Dakota": [
- 701
- ],
- "Ohio": [
- 216,
- 220,
- 234,
- 283,
- 326,
- 330,
- 380,
- 419,
- 436,
- 440,
- 513,
- 567,
- 614,
- 740,
- 937
- ],
- "Oklahoma": [
- 405,
- 539,
- 572,
- 580,
- 918
- ],
- "Oregon": [
- 458,
- 503,
- 541,
- 971
- ],
- "Pennsylvania": [
- 215,
- 223,
- 267,
- 272,
- 412,
- 445,
- 484,
- 570,
- 582,
- 610,
- 717,
- 724,
- 814,
- 835,
- 878
- ],
- "Rhode Island": [
- 401
- ],
- "South Carolina": [
- 803,
- 821,
- 839,
- 843,
- 854,
- 864
- ],
- "South Dakota": [
- 605
- ],
- "Tennessee": [
- 423,
- 615,
- 629,
- 731,
- 865,
- 901,
- 931
- ],
- "Texas": [
- 210,
- 214,
- 254,
- 281,
- 325,
- 346,
- 361,
- 409,
- 430,
- 432,
- 469,
- 512,
- 682,
- 713,
- 726,
- 737,
- 806,
- 817,
- 830,
- 832,
- 903,
- 915,
- 936,
- 940,
- 945,
- 956,
- 972,
- 979
- ],
- "Utah": [
- 385,
- 435,
- 801
- ],
- "Vermont": [
- 802
- ],
- "Virginia": [
- 276,
- 434,
- 540,
- 571,
- 686,
- 703,
- 757,
- 804,
- 826,
- 948
- ],
- "Washington": [
- 202,
- 206,
- 253,
- 360,
- 425,
- 509,
- 564,
- 771
- ],
- "West Virginia": [
- 304,
- 681
- ],
- "Wisconsin": [
- 262,
- 274,
- 353,
- 414,
- 534,
- 608,
- 715,
- 920
- ],
- "Wyoming": [
- 307
- ]
- }
- const canadianStateToNumber = {
- "Alberta": [
- 368,
- 403,
- 568,
- 587,
- 780,
- 825
- ],
- "British Columbia": [
- 236,
- 250,
- 257,
- 604,
- 672,
- 778
- ],
- "Manitoba": [
- 204,
- 431,
- 584
- ],
- "New Brunswick": [
- 428,
- 506
- ],
- "Newfoundland and Labrador": [
- 709,
- 879
- ],
- "Northwest Territories": [
- 867
- ],
- "Nova Scotia": [
- 782,
- 851,
- 902
- ],
- "Nunavut": [
- 867
- ],
- "Ontario": [
- 226,
- 249,
- 289,
- 343,
- 365,
- 382,
- 387,
- 416,
- 437,
- 460,
- 519,
- 537,
- 548,
- 613,
- 647,
- 683,
- 705,
- 742,
- 753,
- 807,
- 905,
- 942
- ],
- "Prince Edward Island": [
- 782,
- 902
- ],
- "Quebec": [
- 263,
- 354,
- 367,
- 418,
- 438,
- 450,
- 468,
- 514,
- 579,
- 581,
- 819,
- 873
- ],
- "Saskatchewan": [
- 306,
- 474,
- 639
- ],
- "Yukon": [
- 867
- ]
- }
- const stateToNumbers = {...usStateToNumbers, ...canadianStateToNumber};
- const usStateZones = {
- "Alabama": "America/Chicago",
- "Alaska": "America/Anchorage",
- "Arizona": "America/Phoenix",
- "Arkansas": "America/Chicago",
- "California": "America/Los_Angeles",
- "Colorado": "America/Denver",
- "Connecticut": "America/New_York",
- "Delaware": "America/New_York",
- "Florida": "America/New_York",
- "Georgia": "America/New_York",
- "Hawaii": "Pacific/Honolulu",
- "Idaho": "America/Boise",
- "Illinois": "America/Chicago",
- "Indiana": "America/Indiana/Indianapolis",
- "Iowa": "America/Chicago",
- "Kansas": "America/Chicago",
- "Kentucky": "America/New_York",
- "Louisiana": "America/Chicago",
- "Maine": "America/New_York",
- "Maryland": "America/New_York",
- "Massachusetts": "America/New_York",
- "Michigan": "America/Detroit",
- "Minnesota": "America/Chicago",
- "Mississippi": "America/Chicago",
- "Missouri": "America/Chicago",
- "Montana": "America/Denver",
- "Nebraska": "America/Chicago",
- "Nevada": "America/Los_Angeles",
- "New Hampshire": "America/New_York",
- "New Jersey": "America/New_York",
- "New Mexico": "America/Denver",
- "New York": "America/New_York",
- "North Carolina": "America/New_York",
- "North Dakota": "America/Chicago",
- "Ohio": "America/New_York",
- "Oklahoma": "America/Chicago",
- "Oregon": "America/Los_Angeles",
- "Pennsylvania": "America/New_York",
- "Rhode Island": "America/New_York",
- "South Carolina": "America/New_York",
- "South Dakota": "America/Chicago",
- "Tennessee": "America/Chicago",
- "Texas": "America/Chicago",
- "Utah": "America/Denver",
- "Vermont": "America/New_York",
- "Virginia": "America/New_York",
- "Washington": "America/Los_Angeles",
- "West Virginia": "America/New_York",
- "Wisconsin": "America/Chicago",
- "Wyoming": "America/Denver"
- }
- const canadianStateZones = {
- "Alberta": "America/Edmonton",
- "British Columbia": "America/Vancouver",
- "Manitoba": "America/Winnipeg",
- "New Brunswick": "America/Moncton",
- "Newfoundland and Labrador": "America/St_Johns",
- "Nova Scotia": "America/Halifax",
- "Ontario": "America/Toronto",
- "Prince Edward Island": "America/Halifax",
- "Quebec": "America/Toronto",
- "Saskatchewan": "America/Regina",
- "Northwest Territories": "America/Yellowknife",
- "Nunavut": "America/Rankin_Inlet",
- "Yukon": "America/Whitehorse"
- }
- const stateZones = {...usStateZones, ...canadianStateZones}
- const fix = (n: string) => {
- let newNumber = n.replace(/[\s\(\)\+\-]/g, "");
- if (!newNumber.startsWith("1")) {
- newNumber = `1${newNumber}`;
- }
- return newNumber;
- }
- const getCode = (n: string) => n.slice(1, 4);
- const getState = (n: string) => {
- const code = Number(getCode(fix(n)));
- for (const [state, codes] of Object.entries(stateToNumbers)) {
- if (codes.includes(code)) {
- return state;
- }
- }
- return undefined;
- }
- const getTz = (n: string) => {
- const state = getState(n);
- return state && stateZones[state];
- }
- console.log(getTz(("1 (678) 361-6626")));
- const numbers = [
- '+1 978-236-7900', '+353868875315', '+33 6 09 37 43 43', '+506 8330 4579', '+972545468084',
- '+1 603-686-1382', '+61422053150', '+1 407-399-1523', '+447796138049', '+19173993847',
- '+61 423 348 833', '+14082639200', '+353861677300', '+61 404 712 139', '\'+1 707-239-0452',
- '+17343475828', '+447772600167', '+5561998000220', '+17038989480', '+65 9236 7873',
- '+1 626-347-6879', '+6596265887', '+1 831-566-7820', '+1 415-366-9672', '+61403562196',
- '+1 908-720-5511', '+919008036795', '+12033002098', '+1 517-260-8798', '+6598188546',
- '+6583032007', '+447971496830', '+447730369920', '+44 79 7970 9938', '+1 843-245-2563',
- '+13103844311', '+1 801-554-2046', '+13475514412', '+1 203-443-6825', '+19496321011',
- '+33 1 58 17 73 05', '+1 781-733-5016', '+1 916-945-7352', '+91 99670 07700', '+16103887553',
- '+17325207613', '+17758003715', '+1 415-627-8795', '+1 407-492-7677', '+17272717746',
- '+1 954-267-5983', '+18054059509', '+1 949-413-9298', '+14083864452', '+16126447915',
- '+12023082186', '+18574983272', '+14252697966', '+12163264531', '+14088398855',
- '+17022411085', '+19098445785', '+14086057554', '+15853620754', '+13017609884',
- '+1 801-362-8898', '(602) 361-7565', '+17024602655', '(678) 361-6626', '+12063319465',
- '+1 818-674-3351', '+16693002633', '+1 714-309-3500', '+17654135025', '+1 609-332-0709',
- '+19164706645', '+1 781-291-9290', '+18566739212', '+1 978-430-6411', '+1 978-407-2669',
- '+1 724-944-6314', '+1 908-385-0940', '+13012331415', '+16178408382', '+19104707587',
- '+14086169518', '+13364806947', '+1 408-981-5497', '+16504306265', '+1 480-223-7272',
- '+13522567790', '+1 248-882-2008', '+1 410-263-5740', '+1 347-831-3962', '+15164138562',
- '+1 416-577-1267', '+1 607-661-9726', '+44 7798 632651', '+12019134437', '+19786211968',
- '+1 610-256-8704', '+1 813-299-9995', '+18609185312', '+1 724-553-0969', '+1 781-277-1202',
- '+1 415-216-7629', '+1 443-413-9080', '+19735566420', '+1 408-966-2662', '+12066017707',
- '+44 20 3457 1067', '+447795613157', '+447873812890'
- ]
- const res = numbers.map((x) => {
- const tz = getTz(x);
- return tz;
- })
- console.log(res.filter(Boolean));
Add Comment
Please, Sign In to add comment