Skip to content

Instantly share code, notes, and snippets.

@raulsananes
Last active September 3, 2017 07:51
Show Gist options
  • Save raulsananes/6d3fa3be81dc29819979723bf95034d3 to your computer and use it in GitHub Desktop.
Save raulsananes/6d3fa3be81dc29819979723bf95034d3 to your computer and use it in GitHub Desktop.
This Google Apps Script will allow you to determine the state and timezone of any phone number in the United States. Please check also http://j.mp/RaulsPhoneCodes
function state(phone){
phonet=phone.toString();
areaCode=phonet.replace(/\D/g,'').substr(0, 3);
areaCodei=Number(areaCode);
switch (areaCodei)
{
case 205:
case 251:
case 256:
case 334:
case 938: return "Alabama";
case 907: return "Alaska";
case 684: return "American Samoa";
case 480:
case 520:
case 602:
case 623:
case 928: return "Arizona";
case 479:
case 501:
case 870: return "Arkansas";
case 209:
case 213:
case 310:
case 323:
case 408:
case 415:
case 424:
case 442:
case 510:
case 530:
case 559:
case 562:
case 619:
case 626:
case 650:
case 657:
case 661:
case 707:
case 714:
case 747:
case 760:
case 805:
case 818:
case 831:
case 858:
case 909:
case 916:
case 925:
case 949:
case 951: return "California";
case 303:
case 719:
case 720:
case 970: return "Colorado";
case 203:
case 475:
case 860: return "Connecticut";
case 302: return "Delaware";
case 239:
case 305:
case 321:
case 352:
case 386:
case 407:
case 561:
case 727:
case 754:
case 772:
case 786:
case 813:
case 850:
case 863:
case 904:
case 941:
case 954: return "Florida";
case 229:
case 404:
case 470:
case 478:
case 678:
case 706:
case 762:
case 770:
case 912: return "Georgia";
case 671: return "Guam";
case 808: return "Hawaii";
case 208: return "Idaho";
case 217:
case 224:
case 309:
case 312:
case 331:
case 618:
case 630:
case 708:
case 773:
case 779:
case 815:
case 847:
case 872: return "Illinois";
case 219:
case 260:
case 317:
case 574:
case 765:
case 812: return "Indiana";
case 319:
case 515:
case 563:
case 641:
case 712: return "Iowa";
case 316:
case 620:
case 785:
case 913: return "Kansas";
case 270:
case 502:
case 606:
case 859: return "Kentucky";
case 225:
case 318:
case 337:
case 504:
case 985: return "Louisiana";
case 207: return "Maine";
case 240:
case 301:
case 410:
case 443: return "Maryland";
case 339:
case 351:
case 413:
case 508:
case 617:
case 774:
case 781:
case 857:
case 978: return "Massachusetts";
case 231:
case 248:
case 269:
case 313:
case 517:
case 586:
case 616:
case 734:
case 810:
case 906:
case 947:
case 989: return "Michigan";
case 218:
case 320:
case 507:
case 612:
case 651:
case 763:
case 952: return "Minnesota";
case 228:
case 601:
case 662:
case 769: return "Mississippi";
case 314:
case 417:
case 573:
case 636:
case 660:
case 816: return "Missouri";
case 406: return "Montana";
case 308:
case 402: return "Nebraska";
case 702:
case 775: return "Nevada";
case 603: return "New Hampshire";
case 201:
case 551:
case 609:
case 732:
case 848:
case 856:
case 862:
case 908:
case 973: return "New Jersey";
case 505:
case 575: return "New Mexico";
case 212:
case 315:
case 347:
case 516:
case 518:
case 585:
case 607:
case 631:
case 646:
case 716:
case 718:
case 845:
case 914:
case 917:
case 929: return "New York";
case 252:
case 336:
case 704:
case 828:
case 910:
case 919:
case 980: return "North Carolina";
case 701: return "North Dakota";
case 216:
case 234:
case 330:
case 419:
case 440:
case 513:
case 567:
case 614:
case 740:
case 937: return "Ohio";
case 405:
case 539:
case 580:
case 918: return "Oklahoma";
case 458:
case 503:
case 541:
case 971: return "Oregon";
case 215:
case 267:
case 412:
case 484:
case 570:
case 610:
case 717:
case 724:
case 814:
case 878: return "Pennsylvania";
case 787:
case 939: return "Puerto Rico";
case 401: return "Rhode Island";
case 803:
case 843:
case 864:
case 605: return "South Dakota";
case 423:
case 615:
case 731:
case 865:
case 901:
case 931: return "Tennessee";
case 210:
case 214:
case 254:
case 281:
case 325:
case 361:
case 409:
case 430:
case 432:
case 469:
case 512:
case 682:
case 713:
case 806:
case 817:
case 830:
case 832:
case 903:
case 915:
case 936:
case 940:
case 956:
case 972:
case 979: return "Texas";
case 385:
case 435:
case 801: return "Utah";
case 802: return "Vermont";
case 340: return "Virgin Islands";
case 276:
case 434:
case 540:
case 571:
case 703:
case 757:
case 804: return "Virginia";
case 202: return "Washington,DC";
case 206:
case 253:
case 360:
case 425:
case 509: return "Washington";
case 304:
case 681: return "West Virginia";
case 262:
case 414:
case 608:
case 715:
case 920: return "Wisconsin";
case 307: return "Wyoming";
default: return "Unknown";
}
}
function timezone(phone){
phonet=phone.toString();
areaCode=phonet.replace(/\D/g,'').substr(0, 3);
areaCodei=Number(areaCode);
switch (areaCodei)
{
case 205:
case 251:
case 256:
case 334:
case 938: return "CT";
case 907: return "UTC-9";
case 684: return "UTC-11";
case 480:
case 520:
case 602:
case 623:
case 928: return "PT or MT";
case 479:
case 501:
case 870: return "CT";
case 209:
case 213:
case 310:
case 323:
case 408:
case 415:
case 424:
case 442:
case 510:
case 530:
case 559:
case 562:
case 619:
case 626:
case 650:
case 657:
case 661:
case 707:
case 714:
case 747:
case 760:
case 805:
case 818:
case 831:
case 858:
case 909:
case 916:
case 925:
case 949:
case 951: return "PT";
case 303:
case 719:
case 720:
case 970: return "MT";
case 203:
case 475:
case 860: return "ET";
case 302: return "ET";
case 239:
case 305:
case 321:
case 352:
case 386:
case 407:
case 561:
case 727:
case 754:
case 772:
case 786:
case 813:
case 850:
case 863:
case 904:
case 941:
case 954: return "ET or CT";
case 229:
case 404:
case 470:
case 478:
case 678:
case 706:
case 762:
case 770:
case 912: return "ET";
case 671: return "UTC+10";
case 808: return "UTC-10";
case 208: return "MT or PT";
case 217:
case 224:
case 309:
case 312:
case 331:
case 618:
case 630:
case 708:
case 773:
case 779:
case 815:
case 847:
case 872: return "CT";
case 219:
case 260:
case 317:
case 574:
case 765:
case 812: return "ET or CT";
case 319:
case 515:
case 563:
case 641:
case 712: return "CT";
case 316:
case 620:
case 785:
case 913: return "CT or MT";
case 270:
case 502:
case 606:
case 859: return "ET or CT";
case 225:
case 318:
case 337:
case 504:
case 985: return "CT";
case 207: return "ET";
case 240:
case 301:
case 410:
case 443: return "ET";
case 339:
case 351:
case 413:
case 508:
case 617:
case 774:
case 781:
case 857:
case 978: return "ET";
case 231:
case 248:
case 269:
case 313:
case 517:
case 586:
case 616:
case 734:
case 810:
case 906:
case 947:
case 989: return "ET or CT";
case 218:
case 320:
case 507:
case 612:
case 651:
case 763:
case 952: return "CT";
case 228:
case 601:
case 662:
case 769: return "CT";
case 314:
case 417:
case 573:
case 636:
case 660:
case 816: return "CT";
case 406: return "MT";
case 308:
case 402: return "MT or CT";
case 702:
case 775: return "PT and MT";
case 603: return "ET";
case 201:
case 551:
case 609:
case 732:
case 848:
case 856:
case 862:
case 908:
case 973: return "ET";
case 505:
case 575: return "MT";
case 212:
case 315:
case 347:
case 516:
case 518:
case 585:
case 607:
case 631:
case 646:
case 716:
case 718:
case 845:
case 914:
case 917:
case 929: return "ET";
case 252:
case 336:
case 704:
case 828:
case 910:
case 919:
case 980: return "ET";
case 701: return "CT or MT";
case 216:
case 234:
case 330:
case 419:
case 440:
case 513:
case 567:
case 614:
case 740:
case 937: return "ET";
case 405:
case 539:
case 580:
case 918: return "CT";
case 458:
case 503:
case 541:
case 971: return "PT or MT";
case 215:
case 267:
case 412:
case 484:
case 570:
case 610:
case 717:
case 724:
case 814:
case 878: return "ET";
case 787:
case 939: return "UTC-4";
case 401: return "ET";
case 803:
case 843:
case 864:
case 605: return "CT or MT";
case 423:
case 615:
case 731:
case 865:
case 901:
case 931: return "CT or ET";
case 210:
case 214:
case 254:
case 281:
case 325:
case 361:
case 409:
case 430:
case 432:
case 469:
case 512:
case 682:
case 713:
case 806:
case 817:
case 830:
case 832:
case 903:
case 915:
case 936:
case 940:
case 956:
case 972:
case 979: return "CT or MT";
case 385:
case 435:
case 801: return "MT";
case 802: return "ET";
case 340: return "UTC-4";
case 276:
case 434:
case 540:
case 571:
case 703:
case 757:
case 804: return "ET";
case 202: return "ET";
case 206:
case 253:
case 360:
case 425:
case 509: return "PT";
case 304:
case 681: return "ET";
case 262:
case 414:
case 608:
case 715:
case 920: return "CT";
case 307: return "MT";
default: return "Unknown";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment