__init__.py 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997
  1. # coding=utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from calendar import timegm
  5. from datetime import timedelta, MAXYEAR
  6. from time import time
  7. from dateutil import relativedelta
  8. from dateutil.tz import tzlocal, tzutc
  9. from faker.utils.datetime_safe import date, datetime, real_date, real_datetime
  10. from faker.utils import is_string
  11. from .. import BaseProvider
  12. localized = True
  13. def datetime_to_timestamp(dt):
  14. if getattr(dt, 'tzinfo', None) is not None:
  15. dt = dt.astimezone(tzutc())
  16. return timegm(dt.timetuple())
  17. def timestamp_to_datetime(timestamp, tzinfo):
  18. if tzinfo is None:
  19. pick = datetime.fromtimestamp(timestamp, tzlocal())
  20. pick = pick.astimezone(tzutc()).replace(tzinfo=None)
  21. else:
  22. pick = datetime.fromtimestamp(timestamp, tzinfo)
  23. return pick
  24. class ParseError(ValueError):
  25. pass
  26. timedelta_pattern = r''
  27. for name, sym in [('years', 'y'), ('weeks', 'w'), ('days', 'd'),
  28. ('hours', 'h'), ('minutes', 'm'), ('seconds', 's')]:
  29. timedelta_pattern += r'((?P<{0}>(?:\+|-)\d+?){1})?'.format(name, sym)
  30. class Provider(BaseProvider):
  31. centuries = [
  32. 'I',
  33. 'II',
  34. 'III',
  35. 'IV',
  36. 'V',
  37. 'VI',
  38. 'VII',
  39. 'VIII',
  40. 'IX',
  41. 'X',
  42. 'XI',
  43. 'XII',
  44. 'XIII',
  45. 'XIV',
  46. 'XV',
  47. 'XVI',
  48. 'XVII',
  49. 'XVIII',
  50. 'XIX',
  51. 'XX',
  52. 'XXI']
  53. countries = [{'timezones': ['Europe/Andorra'],
  54. 'alpha-2-code': 'AD',
  55. 'alpha-3-code': 'AND',
  56. 'continent': 'Europe',
  57. 'name': 'Andorra',
  58. 'capital': 'Andorra la Vella'},
  59. {'timezones': ['Asia/Kabul'],
  60. 'alpha-2-code': 'AF',
  61. 'alpha-3-code': 'AFG',
  62. 'continent': 'Asia',
  63. 'name': 'Afghanistan',
  64. 'capital': 'Kabul'},
  65. {'timezones': ['America/Antigua'],
  66. 'alpha-2-code': 'AG',
  67. 'alpha-3-code': 'ATG',
  68. 'continent': 'North America',
  69. 'name': 'Antigua and Barbuda',
  70. 'capital': "St. John's"},
  71. {'timezones': ['Europe/Tirane'],
  72. 'alpha-2-code': 'AL',
  73. 'alpha-3-code': 'ALB',
  74. 'continent': 'Europe',
  75. 'name': 'Albania',
  76. 'capital': 'Tirana'},
  77. {'timezones': ['Asia/Yerevan'],
  78. 'alpha-2-code': 'AM',
  79. 'alpha-3-code': 'ARM',
  80. 'continent': 'Asia',
  81. 'name': 'Armenia',
  82. 'capital': 'Yerevan'},
  83. {'timezones': ['Africa/Luanda'],
  84. 'alpha-2-code': 'AO',
  85. 'alpha-3-code': 'AGO',
  86. 'continent': 'Africa',
  87. 'name': 'Angola',
  88. 'capital': 'Luanda'},
  89. {'timezones': ['America/Argentina/Buenos_Aires',
  90. 'America/Argentina/Cordoba',
  91. 'America/Argentina/Jujuy',
  92. 'America/Argentina/Tucuman',
  93. 'America/Argentina/Catamarca',
  94. 'America/Argentina/La_Rioja',
  95. 'America/Argentina/San_Juan',
  96. 'America/Argentina/Mendoza',
  97. 'America/Argentina/Rio_Gallegos',
  98. 'America/Argentina/Ushuaia'],
  99. 'alpha-2-code': 'AR',
  100. 'alpha-3-code': 'ARG',
  101. 'continent': 'South America',
  102. 'name': 'Argentina',
  103. 'capital': 'Buenos Aires'},
  104. {'timezones': ['Europe/Vienna'],
  105. 'alpha-2-code': 'AT',
  106. 'alpha-3-code': 'AUT',
  107. 'continent': 'Europe',
  108. 'name': 'Austria',
  109. 'capital': 'Vienna'},
  110. {'timezones': ['Australia/Lord_Howe',
  111. 'Australia/Hobart',
  112. 'Australia/Currie',
  113. 'Australia/Melbourne',
  114. 'Australia/Sydney',
  115. 'Australia/Broken_Hill',
  116. 'Australia/Brisbane',
  117. 'Australia/Lindeman',
  118. 'Australia/Adelaide',
  119. 'Australia/Darwin',
  120. 'Australia/Perth'],
  121. 'alpha-2-code': 'AU',
  122. 'alpha-3-code': 'AUS',
  123. 'continent': 'Oceania',
  124. 'name': 'Australia',
  125. 'capital': 'Canberra'},
  126. {'timezones': ['Asia/Baku'],
  127. 'alpha-2-code': 'AZ',
  128. 'alpha-3-code': 'AZE',
  129. 'continent': 'Asia',
  130. 'name': 'Azerbaijan',
  131. 'capital': 'Baku'},
  132. {'timezones': ['America/Barbados'],
  133. 'alpha-2-code': 'BB',
  134. 'alpha-3-code': 'BRB',
  135. 'continent': 'North America',
  136. 'name': 'Barbados',
  137. 'capital': 'Bridgetown'},
  138. {'timezones': ['Asia/Dhaka'],
  139. 'alpha-2-code': 'BD',
  140. 'alpha-3-code': 'BGD',
  141. 'continent': 'Asia',
  142. 'name': 'Bangladesh',
  143. 'capital': 'Dhaka'},
  144. {'timezones': ['Europe/Brussels'],
  145. 'alpha-2-code': 'BE',
  146. 'alpha-3-code': 'BEL',
  147. 'continent': 'Europe',
  148. 'name': 'Belgium',
  149. 'capital': 'Brussels'},
  150. {'timezones': ['Africa/Ouagadougou'],
  151. 'alpha-2-code': 'BF',
  152. 'alpha-3-code': 'BFA',
  153. 'continent': 'Africa',
  154. 'name': 'Burkina Faso',
  155. 'capital': 'Ouagadougou'},
  156. {'timezones': ['Europe/Sofia'],
  157. 'alpha-2-code': 'BG',
  158. 'alpha-3-code': 'BGR',
  159. 'continent': 'Europe',
  160. 'name': 'Bulgaria',
  161. 'capital': 'Sofia'},
  162. {'timezones': ['Asia/Bahrain'],
  163. 'alpha-2-code': 'BH',
  164. 'alpha-3-code': 'BHR',
  165. 'continent': 'Asia',
  166. 'name': 'Bahrain',
  167. 'capital': 'Manama'},
  168. {'timezones': ['Africa/Bujumbura'],
  169. 'alpha-2-code': 'BI',
  170. 'alpha-3-code': 'BDI',
  171. 'continent': 'Africa',
  172. 'name': 'Burundi',
  173. 'capital': 'Bujumbura'},
  174. {'timezones': ['Africa/Porto-Novo'],
  175. 'alpha-2-code': 'BJ',
  176. 'alpha-3-code': 'BEN',
  177. 'continent': 'Africa',
  178. 'name': 'Benin',
  179. 'capital': 'Porto-Novo'},
  180. {'timezones': ['Asia/Brunei'],
  181. 'alpha-2-code': 'BN',
  182. 'alpha-3-code': 'BRN',
  183. 'continent': 'Asia',
  184. 'name': 'Brunei Darussalam',
  185. 'capital': 'Bandar Seri Begawan'},
  186. {'timezones': ['America/La_Paz'],
  187. 'alpha-2-code': 'BO',
  188. 'alpha-3-code': 'BOL',
  189. 'continent': 'South America',
  190. 'name': 'Bolivia',
  191. 'capital': 'Sucre'},
  192. {'timezones': ['America/Noronha',
  193. 'America/Belem',
  194. 'America/Fortaleza',
  195. 'America/Recife',
  196. 'America/Araguaina',
  197. 'America/Maceio',
  198. 'America/Bahia',
  199. 'America/Sao_Paulo',
  200. 'America/Campo_Grande',
  201. 'America/Cuiaba',
  202. 'America/Porto_Velho',
  203. 'America/Boa_Vista',
  204. 'America/Manaus',
  205. 'America/Eirunepe',
  206. 'America/Rio_Branco'],
  207. 'alpha-2-code': 'BR',
  208. 'alpha-3-code': 'BRA',
  209. 'continent': 'South America',
  210. 'name': 'Brazil',
  211. 'capital': 'Bras\xc3\xadlia'},
  212. {'timezones': ['America/Nassau'],
  213. 'alpha-2-code': 'BS',
  214. 'alpha-3-code': 'BHS',
  215. 'continent': 'North America',
  216. 'name': 'Bahamas',
  217. 'capital': 'Nassau'},
  218. {'timezones': ['Asia/Thimphu'],
  219. 'alpha-2-code': 'BT',
  220. 'alpha-3-code': 'BTN',
  221. 'continent': 'Asia',
  222. 'name': 'Bhutan',
  223. 'capital': 'Thimphu'},
  224. {'timezones': ['Africa/Gaborone'],
  225. 'alpha-2-code': 'BW',
  226. 'alpha-3-code': 'BWA',
  227. 'continent': 'Africa',
  228. 'name': 'Botswana',
  229. 'capital': 'Gaborone'},
  230. {'timezones': ['Europe/Minsk'],
  231. 'alpha-2-code': 'BY',
  232. 'alpha-3-code': 'BLR',
  233. 'continent': 'Europe',
  234. 'name': 'Belarus',
  235. 'capital': 'Minsk'},
  236. {'timezones': ['America/Belize'],
  237. 'alpha-2-code': 'BZ',
  238. 'alpha-3-code': 'BLZ',
  239. 'continent': 'North America',
  240. 'name': 'Belize',
  241. 'capital': 'Belmopan'},
  242. {'timezones': ['America/St_Johns',
  243. 'America/Halifax',
  244. 'America/Glace_Bay',
  245. 'America/Moncton',
  246. 'America/Goose_Bay',
  247. 'America/Blanc-Sablon',
  248. 'America/Montreal',
  249. 'America/Toronto',
  250. 'America/Nipigon',
  251. 'America/Thunder_Bay',
  252. 'America/Pangnirtung',
  253. 'America/Iqaluit',
  254. 'America/Atikokan',
  255. 'America/Rankin_Inlet',
  256. 'America/Winnipeg',
  257. 'America/Rainy_River',
  258. 'America/Cambridge_Bay',
  259. 'America/Regina',
  260. 'America/Swift_Current',
  261. 'America/Edmonton',
  262. 'America/Yellowknife',
  263. 'America/Inuvik',
  264. 'America/Dawson_Creek',
  265. 'America/Vancouver',
  266. 'America/Whitehorse',
  267. 'America/Dawson'],
  268. 'alpha-2-code': 'CA',
  269. 'alpha-3-code': 'CAN',
  270. 'continent': 'North America',
  271. 'name': 'Canada',
  272. 'capital': 'Ottawa'},
  273. {'timezones': ['Africa/Kinshasa',
  274. 'Africa/Lubumbashi'],
  275. 'alpha-2-code': 'CD',
  276. 'alpha-3-code': 'COD',
  277. 'continent': 'Africa',
  278. 'name': 'Democratic Republic of the Congo',
  279. 'capital': 'Kinshasa'},
  280. {'timezones': ['Africa/Brazzaville'],
  281. 'alpha-2-code': 'CG',
  282. 'alpha-3-code': 'COG',
  283. 'continent': 'Africa',
  284. 'name': 'Republic of the Congo',
  285. 'capital': 'Brazzaville'},
  286. {'timezones': ['Africa/Abidjan'],
  287. 'alpha-2-code': 'CI',
  288. 'alpha-3-code': 'CIV',
  289. 'continent': 'Africa',
  290. 'name': "C\xc3\xb4te d'Ivoire",
  291. 'capital': 'Yamoussoukro'},
  292. {'timezones': ['America/Santiago',
  293. 'Pacific/Easter'],
  294. 'alpha-2-code': 'CL',
  295. 'alpha-3-code': 'CHL',
  296. 'continent': 'South America',
  297. 'name': 'Chile',
  298. 'capital': 'Santiago'},
  299. {'timezones': ['Africa/Douala'],
  300. 'alpha-2-code': 'CM',
  301. 'alpha-3-code': 'CMR',
  302. 'continent': 'Africa',
  303. 'name': 'Cameroon',
  304. 'capital': 'Yaound\xc3\xa9'},
  305. {'timezones': ['Asia/Shanghai',
  306. 'Asia/Harbin',
  307. 'Asia/Chongqing',
  308. 'Asia/Urumqi',
  309. 'Asia/Kashgar'],
  310. 'alpha-2-code': 'CN',
  311. 'alpha-3-code': 'CHN',
  312. 'continent': 'Asia',
  313. 'name': "People's Republic of China",
  314. 'capital': 'Beijing'},
  315. {'timezones': ['America/Bogota'],
  316. 'alpha-2-code': 'CO',
  317. 'alpha-3-code': 'COL',
  318. 'continent': 'South America',
  319. 'name': 'Colombia',
  320. 'capital': 'Bogot\xc3\xa1'},
  321. {'timezones': ['America/Costa_Rica'],
  322. 'alpha-2-code': 'CR',
  323. 'alpha-3-code': 'CRI',
  324. 'continent': 'North America',
  325. 'name': 'Costa Rica',
  326. 'capital': 'San Jos\xc3\xa9'},
  327. {'timezones': ['America/Havana'],
  328. 'alpha-2-code': 'CU',
  329. 'alpha-3-code': 'CUB',
  330. 'continent': 'North America',
  331. 'name': 'Cuba',
  332. 'capital': 'Havana'},
  333. {'timezones': ['Atlantic/Cape_Verde'],
  334. 'alpha-2-code': 'CV',
  335. 'alpha-3-code': 'CPV',
  336. 'continent': 'Africa',
  337. 'name': 'Cape Verde',
  338. 'capital': 'Praia'},
  339. {'timezones': ['Asia/Nicosia'],
  340. 'alpha-2-code': 'CY',
  341. 'alpha-3-code': 'CYP',
  342. 'continent': 'Asia',
  343. 'name': 'Cyprus',
  344. 'capital': 'Nicosia'},
  345. {'timezones': ['Europe/Prague'],
  346. 'alpha-2-code': 'CZ',
  347. 'alpha-3-code': 'CZE',
  348. 'continent': 'Europe',
  349. 'name': 'Czech Republic',
  350. 'capital': 'Prague'},
  351. {'timezones': ['Europe/Berlin'],
  352. 'alpha-2-code': 'DE',
  353. 'alpha-3-code': 'DEU',
  354. 'continent': 'Europe',
  355. 'name': 'Germany',
  356. 'capital': 'Berlin'},
  357. {'timezones': ['Africa/Djibouti'],
  358. 'alpha-2-code': 'DJ',
  359. 'alpha-3-code': 'DJI',
  360. 'continent': 'Africa',
  361. 'name': 'Djibouti',
  362. 'capital': 'Djibouti City'},
  363. {'timezones': ['Europe/Copenhagen'],
  364. 'alpha-2-code': 'DK',
  365. 'alpha-3-code': 'DNK',
  366. 'continent': 'Europe',
  367. 'name': 'Denmark',
  368. 'capital': 'Copenhagen'},
  369. {'timezones': ['America/Dominica'],
  370. 'alpha-2-code': 'DM',
  371. 'alpha-3-code': 'DMA',
  372. 'continent': 'North America',
  373. 'name': 'Dominica',
  374. 'capital': 'Roseau'},
  375. {'timezones': ['America/Santo_Domingo'],
  376. 'alpha-2-code': 'DO',
  377. 'alpha-3-code': 'DOM',
  378. 'continent': 'North America',
  379. 'name': 'Dominican Republic',
  380. 'capital': 'Santo Domingo'},
  381. {'timezones': ['America/Guayaquil',
  382. 'Pacific/Galapagos'],
  383. 'alpha-2-code': 'EC',
  384. 'alpha-3-code': 'ECU',
  385. 'continent': 'South America',
  386. 'name': 'Ecuador',
  387. 'capital': 'Quito'},
  388. {'timezones': ['Europe/Tallinn'],
  389. 'alpha-2-code': 'EE',
  390. 'alpha-3-code': 'EST',
  391. 'continent': 'Europe',
  392. 'name': 'Estonia',
  393. 'capital': 'Tallinn'},
  394. {'timezones': ['Africa/Cairo'],
  395. 'alpha-2-code': 'EG',
  396. 'alpha-3-code': 'EGY',
  397. 'continent': 'Africa',
  398. 'name': 'Egypt',
  399. 'capital': 'Cairo'},
  400. {'timezones': ['Africa/Asmera'],
  401. 'alpha-2-code': 'ER',
  402. 'alpha-3-code': 'ERI',
  403. 'continent': 'Africa',
  404. 'name': 'Eritrea',
  405. 'capital': 'Asmara'},
  406. {'timezones': ['Africa/Addis_Ababa'],
  407. 'alpha-2-code': 'ET',
  408. 'alpha-3-code': 'ETH',
  409. 'continent': 'Africa',
  410. 'name': 'Ethiopia',
  411. 'capital': 'Addis Ababa'},
  412. {'timezones': ['Europe/Helsinki'],
  413. 'alpha-2-code': 'FI',
  414. 'alpha-3-code': 'FIN',
  415. 'continent': 'Europe',
  416. 'name': 'Finland',
  417. 'capital': 'Helsinki'},
  418. {'timezones': ['Pacific/Fiji'],
  419. 'alpha-2-code': 'FJ',
  420. 'alpha-3-code': 'FJI',
  421. 'continent': 'Oceania',
  422. 'name': 'Fiji',
  423. 'capital': 'Suva'},
  424. {'timezones': ['Europe/Paris'],
  425. 'alpha-2-code': 'FR',
  426. 'alpha-3-code': 'FRA',
  427. 'continent': 'Europe',
  428. 'name': 'France',
  429. 'capital': 'Paris'},
  430. {'timezones': ['Africa/Libreville'],
  431. 'alpha-2-code': 'GA',
  432. 'alpha-3-code': 'GAB',
  433. 'continent': 'Africa',
  434. 'name': 'Gabon',
  435. 'capital': 'Libreville'},
  436. {'timezones': ['Asia/Tbilisi'],
  437. 'alpha-2-code': 'GE',
  438. 'alpha-3-code': 'GEO',
  439. 'continent': 'Asia',
  440. 'name': 'Georgia',
  441. 'capital': 'Tbilisi'},
  442. {'timezones': ['Africa/Accra'],
  443. 'alpha-2-code': 'GH',
  444. 'alpha-3-code': 'GHA',
  445. 'continent': 'Africa',
  446. 'name': 'Ghana',
  447. 'capital': 'Accra'},
  448. {'timezones': ['Africa/Banjul'],
  449. 'alpha-2-code': 'GM',
  450. 'alpha-3-code': 'GMB',
  451. 'continent': 'Africa',
  452. 'name': 'The Gambia',
  453. 'capital': 'Banjul'},
  454. {'timezones': ['Africa/Conakry'],
  455. 'alpha-2-code': 'GN',
  456. 'alpha-3-code': 'GIN',
  457. 'continent': 'Africa',
  458. 'name': 'Guinea',
  459. 'capital': 'Conakry'},
  460. {'timezones': ['Europe/Athens'],
  461. 'alpha-2-code': 'GR',
  462. 'alpha-3-code': 'GRC',
  463. 'continent': 'Europe',
  464. 'name': 'Greece',
  465. 'capital': 'Athens'},
  466. {'timezones': ['America/Guatemala'],
  467. 'alpha-2-code': 'GT',
  468. 'alpha-3-code': 'GTM',
  469. 'continent': 'North America',
  470. 'name': 'Guatemala',
  471. 'capital': 'Guatemala City'},
  472. {'timezones': ['America/Guatemala'],
  473. 'alpha-2-code': 'HT',
  474. 'alpha-3-code': 'HTI',
  475. 'continent': 'North America',
  476. 'name': 'Haiti',
  477. 'capital': 'Port-au-Prince'},
  478. {'timezones': ['Africa/Bissau'],
  479. 'alpha-2-code': 'GW',
  480. 'alpha-3-code': 'GNB',
  481. 'continent': 'Africa',
  482. 'name': 'Guinea-Bissau',
  483. 'capital': 'Bissau'},
  484. {'timezones': ['America/Guyana'],
  485. 'alpha-2-code': 'GY',
  486. 'alpha-3-code': 'GUY',
  487. 'continent': 'South America',
  488. 'name': 'Guyana',
  489. 'capital': 'Georgetown'},
  490. {'timezones': ['America/Tegucigalpa'],
  491. 'alpha-2-code': 'HN',
  492. 'alpha-3-code': 'HND',
  493. 'continent': 'North America',
  494. 'name': 'Honduras',
  495. 'capital': 'Tegucigalpa'},
  496. {'timezones': ['Europe/Budapest'],
  497. 'alpha-2-code': 'HU',
  498. 'alpha-3-code': 'HUN',
  499. 'continent': 'Europe',
  500. 'name': 'Hungary',
  501. 'capital': 'Budapest'},
  502. {'timezones': ['Asia/Jakarta',
  503. 'Asia/Pontianak',
  504. 'Asia/Makassar',
  505. 'Asia/Jayapura'],
  506. 'alpha-2-code': 'ID',
  507. 'alpha-3-code': 'IDN',
  508. 'continent': 'Asia',
  509. 'name': 'Indonesia',
  510. 'capital': 'Jakarta'},
  511. {'timezones': ['Europe/Dublin'],
  512. 'alpha-2-code': 'IE',
  513. 'alpha-3-code': 'IRL',
  514. 'continent': 'Europe',
  515. 'name': 'Republic of Ireland',
  516. 'capital': 'Dublin'},
  517. {'timezones': ['Asia/Jerusalem'],
  518. 'alpha-2-code': 'IL',
  519. 'alpha-3-code': 'ISR',
  520. 'continent': 'Asia',
  521. 'name': 'Israel',
  522. 'capital': 'Jerusalem'},
  523. {'timezones': ['Asia/Calcutta'],
  524. 'alpha-2-code': 'IN',
  525. 'alpha-3-code': 'IND',
  526. 'continent': 'Asia',
  527. 'name': 'India',
  528. 'capital': 'New Delhi'},
  529. {'timezones': ['Asia/Baghdad'],
  530. 'alpha-2-code': 'IQ',
  531. 'alpha-3-code': 'IRQ',
  532. 'continent': 'Asia',
  533. 'name': 'Iraq',
  534. 'capital': 'Baghdad'},
  535. {'timezones': ['Asia/Tehran'],
  536. 'alpha-2-code': 'IR',
  537. 'alpha-3-code': 'IRN',
  538. 'continent': 'Asia',
  539. 'name': 'Iran',
  540. 'capital': 'Tehran'},
  541. {'timezones': ['Atlantic/Reykjavik'],
  542. 'alpha-2-code': 'IS',
  543. 'alpha-3-code': 'ISL',
  544. 'continent': 'Europe',
  545. 'name': 'Iceland',
  546. 'capital': 'Reykjav\xc3\xadk'},
  547. {'timezones': ['Europe/Rome'],
  548. 'alpha-2-code': 'IT',
  549. 'alpha-3-code': 'ITA',
  550. 'continent': 'Europe',
  551. 'name': 'Italy',
  552. 'capital': 'Rome'},
  553. {'timezones': ['America/Jamaica'],
  554. 'alpha-2-code': 'JM',
  555. 'alpha-3-code': 'JAM',
  556. 'continent': 'North America',
  557. 'name': 'Jamaica',
  558. 'capital': 'Kingston'},
  559. {'timezones': ['Asia/Amman'],
  560. 'alpha-2-code': 'JO',
  561. 'alpha-3-code': 'JOR',
  562. 'continent': 'Asia',
  563. 'name': 'Jordan',
  564. 'capital': 'Amman'},
  565. {'timezones': ['Asia/Tokyo'],
  566. 'alpha-2-code': 'JP',
  567. 'alpha-3-code': 'JPN',
  568. 'continent': 'Asia',
  569. 'name': 'Japan',
  570. 'capital': 'Tokyo'},
  571. {'timezones': ['Africa/Nairobi'],
  572. 'alpha-2-code': 'KE',
  573. 'alpha-3-code': 'KEN',
  574. 'continent': 'Africa',
  575. 'name': 'Kenya',
  576. 'capital': 'Nairobi'},
  577. {'timezones': ['Asia/Bishkek'],
  578. 'alpha-2-code': 'KG',
  579. 'alpha-3-code': 'KGZ',
  580. 'continent': 'Asia',
  581. 'name': 'Kyrgyzstan',
  582. 'capital': 'Bishkek'},
  583. {'timezones': ['Pacific/Tarawa',
  584. 'Pacific/Enderbury',
  585. 'Pacific/Kiritimati'],
  586. 'alpha-2-code': 'KI',
  587. 'alpha-3-code': 'KIR',
  588. 'continent': 'Oceania',
  589. 'name': 'Kiribati',
  590. 'capital': 'Tarawa'},
  591. {'timezones': ['Asia/Pyongyang'],
  592. 'alpha-2-code': 'KP',
  593. 'alpha-3-code': 'PRK',
  594. 'continent': 'Asia',
  595. 'name': 'North Korea',
  596. 'capital': 'Pyongyang'},
  597. {'timezones': ['Asia/Seoul'],
  598. 'alpha-2-code': 'KR',
  599. 'alpha-3-code': 'KOR',
  600. 'continent': 'Asia',
  601. 'name': 'South Korea',
  602. 'capital': 'Seoul'},
  603. {'timezones': ['Asia/Kuwait'],
  604. 'alpha-2-code': 'KW',
  605. 'alpha-3-code': 'KWT',
  606. 'continent': 'Asia',
  607. 'name': 'Kuwait',
  608. 'capital': 'Kuwait City'},
  609. {'timezones': ['Asia/Beirut'],
  610. 'alpha-2-code': 'LB',
  611. 'alpha-3-code': 'LBN',
  612. 'continent': 'Asia',
  613. 'name': 'Lebanon',
  614. 'capital': 'Beirut'},
  615. {'timezones': ['Europe/Vaduz'],
  616. 'alpha-2-code': 'LI',
  617. 'alpha-3-code': 'LIE',
  618. 'continent': 'Europe',
  619. 'name': 'Liechtenstein',
  620. 'capital': 'Vaduz'},
  621. {'timezones': ['Africa/Monrovia'],
  622. 'alpha-2-code': 'LR',
  623. 'alpha-3-code': 'LBR',
  624. 'continent': 'Africa',
  625. 'name': 'Liberia',
  626. 'capital': 'Monrovia'},
  627. {'timezones': ['Africa/Maseru'],
  628. 'alpha-2-code': 'LS',
  629. 'alpha-3-code': 'LSO',
  630. 'continent': 'Africa',
  631. 'name': 'Lesotho',
  632. 'capital': 'Maseru'},
  633. {'timezones': ['Europe/Vilnius'],
  634. 'alpha-2-code': 'LT',
  635. 'alpha-3-code': 'LTU',
  636. 'continent': 'Europe',
  637. 'name': 'Lithuania',
  638. 'capital': 'Vilnius'},
  639. {'timezones': ['Europe/Luxembourg'],
  640. 'alpha-2-code': 'LU',
  641. 'alpha-3-code': 'LUX',
  642. 'continent': 'Europe',
  643. 'name': 'Luxembourg',
  644. 'capital': 'Luxembourg City'},
  645. {'timezones': ['Europe/Riga'],
  646. 'alpha-2-code': 'LV',
  647. 'alpha-3-code': 'LVA',
  648. 'continent': 'Europe',
  649. 'name': 'Latvia',
  650. 'capital': 'Riga'},
  651. {'timezones': ['Africa/Tripoli'],
  652. 'alpha-2-code': 'LY',
  653. 'alpha-3-code': 'LBY',
  654. 'continent': 'Africa',
  655. 'name': 'Libya',
  656. 'capital': 'Tripoli'},
  657. {'timezones': ['Indian/Antananarivo'],
  658. 'alpha-2-code': 'MG',
  659. 'alpha-3-code': 'MDG',
  660. 'continent': 'Africa',
  661. 'name': 'Madagascar',
  662. 'capital': 'Antananarivo'},
  663. {'timezones': ['Pacific/Majuro',
  664. 'Pacific/Kwajalein'],
  665. 'alpha-2-code': 'MH',
  666. 'alpha-3-code': 'MHL',
  667. 'continent': 'Oceania',
  668. 'name': 'Marshall Islands',
  669. 'capital': 'Majuro'},
  670. {'timezones': ['Europe/Skopje'],
  671. 'alpha-2-code': 'MK',
  672. 'alpha-3-code': 'MKD',
  673. 'continent': 'Europe',
  674. 'name': 'Macedonia',
  675. 'capital': 'Skopje'},
  676. {'timezones': ['Africa/Bamako'],
  677. 'alpha-2-code': 'ML',
  678. 'alpha-3-code': 'MLI',
  679. 'continent': 'Africa',
  680. 'name': 'Mali',
  681. 'capital': 'Bamako'},
  682. {'timezones': ['Asia/Rangoon'],
  683. 'alpha-2-code': 'MM',
  684. 'alpha-3-code': 'MMR',
  685. 'continent': 'Asia',
  686. 'name': 'Myanmar',
  687. 'capital': 'Naypyidaw'},
  688. {'timezones': ['Asia/Ulaanbaatar',
  689. 'Asia/Hovd',
  690. 'Asia/Choibalsan'],
  691. 'alpha-2-code': 'MN',
  692. 'alpha-3-code': 'MNG',
  693. 'continent': 'Asia',
  694. 'name': 'Mongolia',
  695. 'capital': 'Ulaanbaatar'},
  696. {'timezones': ['Africa/Nouakchott'],
  697. 'alpha-2-code': 'MR',
  698. 'alpha-3-code': 'MRT',
  699. 'continent': 'Africa',
  700. 'name': 'Mauritania',
  701. 'capital': 'Nouakchott'},
  702. {'timezones': ['Europe/Malta'],
  703. 'alpha-2-code': 'MT',
  704. 'alpha-3-code': 'MLT',
  705. 'continent': 'Europe',
  706. 'name': 'Malta',
  707. 'capital': 'Valletta'},
  708. {'timezones': ['Indian/Mauritius'],
  709. 'alpha-2-code': 'MU',
  710. 'alpha-3-code': 'MUS',
  711. 'continent': 'Africa',
  712. 'name': 'Mauritius',
  713. 'capital': 'Port Louis'},
  714. {'timezones': ['Indian/Maldives'],
  715. 'alpha-2-code': 'MV',
  716. 'alpha-3-code': 'MDV',
  717. 'continent': 'Asia',
  718. 'name': 'Maldives',
  719. 'capital': 'Mal\xc3\xa9'},
  720. {'timezones': ['Africa/Blantyre'],
  721. 'alpha-2-code': 'MW',
  722. 'alpha-3-code': 'MWI',
  723. 'continent': 'Africa',
  724. 'name': 'Malawi',
  725. 'capital': 'Lilongwe'},
  726. {'timezones': ['America/Mexico_City',
  727. 'America/Cancun',
  728. 'America/Merida',
  729. 'America/Monterrey',
  730. 'America/Mazatlan',
  731. 'America/Chihuahua',
  732. 'America/Hermosillo',
  733. 'America/Tijuana'],
  734. 'alpha-2-code': 'MX',
  735. 'alpha-3-code': 'MEX',
  736. 'continent': 'North America',
  737. 'name': 'Mexico',
  738. 'capital': 'Mexico City'},
  739. {'timezones': ['Asia/Kuala_Lumpur',
  740. 'Asia/Kuching'],
  741. 'alpha-2-code': 'MY',
  742. 'alpha-3-code': 'MYS',
  743. 'continent': 'Asia',
  744. 'name': 'Malaysia',
  745. 'capital': 'Kuala Lumpur'},
  746. {'timezones': ['Africa/Maputo'],
  747. 'alpha-2-code': 'MZ',
  748. 'alpha-3-code': 'MOZ',
  749. 'continent': 'Africa',
  750. 'name': 'Mozambique',
  751. 'capital': 'Maputo'},
  752. {'timezones': ['Africa/Windhoek'],
  753. 'alpha-2-code': 'NA',
  754. 'alpha-3-code': 'NAM',
  755. 'continent': 'Africa',
  756. 'name': 'Namibia',
  757. 'capital': 'Windhoek'},
  758. {'timezones': ['Africa/Niamey'],
  759. 'alpha-2-code': 'NE',
  760. 'alpha-3-code': 'NER',
  761. 'continent': 'Africa',
  762. 'name': 'Niger',
  763. 'capital': 'Niamey'},
  764. {'timezones': ['Africa/Lagos'],
  765. 'alpha-2-code': 'NG',
  766. 'alpha-3-code': 'NGA',
  767. 'continent': 'Africa',
  768. 'name': 'Nigeria',
  769. 'capital': 'Abuja'},
  770. {'timezones': ['America/Managua'],
  771. 'alpha-2-code': 'NI',
  772. 'alpha-3-code': 'NIC',
  773. 'continent': 'North America',
  774. 'name': 'Nicaragua',
  775. 'capital': 'Managua'},
  776. {'timezones': ['Europe/Amsterdam'],
  777. 'alpha-2-code': 'NL',
  778. 'alpha-3-code': 'NLD',
  779. 'continent': 'Europe',
  780. 'name': 'Kingdom of the Netherlands',
  781. 'capital': 'Amsterdam'},
  782. {'timezones': ['Europe/Oslo'],
  783. 'alpha-2-code': 'NO',
  784. 'alpha-3-code': 'NOR',
  785. 'continent': 'Europe',
  786. 'name': 'Norway',
  787. 'capital': 'Oslo'},
  788. {'timezones': ['Asia/Katmandu'],
  789. 'alpha-2-code': 'NP',
  790. 'alpha-3-code': 'NPL',
  791. 'continent': 'Asia',
  792. 'name': 'Nepal',
  793. 'capital': 'Kathmandu'},
  794. {'timezones': ['Pacific/Nauru'],
  795. 'alpha-2-code': 'NR',
  796. 'alpha-3-code': 'NRU',
  797. 'continent': 'Oceania',
  798. 'name': 'Nauru',
  799. 'capital': 'Yaren'},
  800. {'timezones': ['Pacific/Auckland',
  801. 'Pacific/Chatham'],
  802. 'alpha-2-code': 'NZ',
  803. 'alpha-3-code': 'NZL',
  804. 'continent': 'Oceania',
  805. 'name': 'New Zealand',
  806. 'capital': 'Wellington'},
  807. {'timezones': ['Asia/Muscat'],
  808. 'alpha-2-code': 'OM',
  809. 'alpha-3-code': 'OMN',
  810. 'continent': 'Asia',
  811. 'name': 'Oman',
  812. 'capital': 'Muscat'},
  813. {'timezones': ['America/Panama'],
  814. 'alpha-2-code': 'PA',
  815. 'alpha-3-code': 'PAN',
  816. 'continent': 'North America',
  817. 'name': 'Panama',
  818. 'capital': 'Panama City'},
  819. {'timezones': ['America/Lima'],
  820. 'alpha-2-code': 'PE',
  821. 'alpha-3-code': 'PER',
  822. 'continent': 'South America',
  823. 'name': 'Peru',
  824. 'capital': 'Lima'},
  825. {'timezones': ['Pacific/Port_Moresby'],
  826. 'alpha-2-code': 'PG',
  827. 'alpha-3-code': 'PNG',
  828. 'continent': 'Oceania',
  829. 'name': 'Papua New Guinea',
  830. 'capital': 'Port Moresby'},
  831. {'timezones': ['Asia/Manila'],
  832. 'alpha-2-code': 'PH',
  833. 'alpha-3-code': 'PHL',
  834. 'continent': 'Asia',
  835. 'name': 'Philippines',
  836. 'capital': 'Manila'},
  837. {'timezones': ['Asia/Karachi'],
  838. 'alpha-2-code': 'PK',
  839. 'alpha-3-code': 'PAK',
  840. 'continent': 'Asia',
  841. 'name': 'Pakistan',
  842. 'capital': 'Islamabad'},
  843. {'timezones': ['Europe/Warsaw'],
  844. 'alpha-2-code': 'PL',
  845. 'alpha-3-code': 'POL',
  846. 'continent': 'Europe',
  847. 'name': 'Poland',
  848. 'capital': 'Warsaw'},
  849. {'timezones': ['Europe/Lisbon',
  850. 'Atlantic/Madeira',
  851. 'Atlantic/Azores'],
  852. 'alpha-2-code': 'PT',
  853. 'alpha-3-code': 'PRT',
  854. 'continent': 'Europe',
  855. 'name': 'Portugal',
  856. 'capital': 'Lisbon'},
  857. {'timezones': ['Pacific/Palau'],
  858. 'alpha-2-code': 'PW',
  859. 'alpha-3-code': 'PLW',
  860. 'continent': 'Oceania',
  861. 'name': 'Palau',
  862. 'capital': 'Ngerulmud'},
  863. {'timezones': ['America/Asuncion'],
  864. 'alpha-2-code': 'PY',
  865. 'alpha-3-code': 'PRY',
  866. 'continent': 'South America',
  867. 'name': 'Paraguay',
  868. 'capital': 'Asunci\xc3\xb3n'},
  869. {'timezones': ['Asia/Qatar'],
  870. 'alpha-2-code': 'QA',
  871. 'alpha-3-code': 'QAT',
  872. 'continent': 'Asia',
  873. 'name': 'Qatar',
  874. 'capital': 'Doha'},
  875. {'timezones': ['Europe/Bucharest'],
  876. 'alpha-2-code': 'RO',
  877. 'alpha-3-code': 'ROU',
  878. 'continent': 'Europe',
  879. 'name': 'Romania',
  880. 'capital': 'Bucharest'},
  881. {'timezones': ['Europe/Kaliningrad',
  882. 'Europe/Moscow',
  883. 'Europe/Volgograd',
  884. 'Europe/Samara',
  885. 'Asia/Yekaterinburg',
  886. 'Asia/Omsk',
  887. 'Asia/Novosibirsk',
  888. 'Asia/Krasnoyarsk',
  889. 'Asia/Irkutsk',
  890. 'Asia/Yakutsk',
  891. 'Asia/Vladivostok',
  892. 'Asia/Sakhalin',
  893. 'Asia/Magadan',
  894. 'Asia/Kamchatka',
  895. 'Asia/Anadyr'],
  896. 'alpha-2-code': 'RU',
  897. 'alpha-3-code': 'RUS',
  898. 'continent': 'Europe',
  899. 'name': 'Russia',
  900. 'capital': 'Moscow'},
  901. {'timezones': ['Africa/Kigali'],
  902. 'alpha-2-code': 'RW',
  903. 'alpha-3-code': 'RWA',
  904. 'continent': 'Africa',
  905. 'name': 'Rwanda',
  906. 'capital': 'Kigali'},
  907. {'timezones': ['Asia/Riyadh'],
  908. 'alpha-2-code': 'SA',
  909. 'alpha-3-code': 'SAU',
  910. 'continent': 'Asia',
  911. 'name': 'Saudi Arabia',
  912. 'capital': 'Riyadh'},
  913. {'timezones': ['Pacific/Guadalcanal'],
  914. 'alpha-2-code': 'SB',
  915. 'alpha-3-code': 'SLB',
  916. 'continent': 'Oceania',
  917. 'name': 'Solomon Islands',
  918. 'capital': 'Honiara'},
  919. {'timezones': ['Indian/Mahe'],
  920. 'alpha-2-code': 'SC',
  921. 'alpha-3-code': 'SYC',
  922. 'continent': 'Africa',
  923. 'name': 'Seychelles',
  924. 'capital': 'Victoria'},
  925. {'timezones': ['Africa/Khartoum'],
  926. 'alpha-2-code': 'SD',
  927. 'alpha-3-code': 'SDN',
  928. 'continent': 'Africa',
  929. 'name': 'Sudan',
  930. 'capital': 'Khartoum'},
  931. {'timezones': ['Europe/Stockholm'],
  932. 'alpha-2-code': 'SE',
  933. 'alpha-3-code': 'SWE',
  934. 'continent': 'Europe',
  935. 'name': 'Sweden',
  936. 'capital': 'Stockholm'},
  937. {'timezones': ['Asia/Singapore'],
  938. 'alpha-2-code': 'SG',
  939. 'alpha-3-code': 'SGP',
  940. 'continent': 'Asia',
  941. 'name': 'Singapore',
  942. 'capital': 'Singapore'},
  943. {'timezones': ['Europe/Ljubljana'],
  944. 'alpha-2-code': 'SI',
  945. 'alpha-3-code': 'SVN',
  946. 'continent': 'Europe',
  947. 'name': 'Slovenia',
  948. 'capital': 'Ljubljana'},
  949. {'timezones': ['Europe/Bratislava'],
  950. 'alpha-2-code': 'SK',
  951. 'alpha-3-code': 'SVK',
  952. 'continent': 'Europe',
  953. 'name': 'Slovakia',
  954. 'capital': 'Bratislava'},
  955. {'timezones': ['Africa/Freetown'],
  956. 'alpha-2-code': 'SL',
  957. 'alpha-3-code': 'SLE',
  958. 'continent': 'Africa',
  959. 'name': 'Sierra Leone',
  960. 'capital': 'Freetown'},
  961. {'timezones': ['Europe/San_Marino'],
  962. 'alpha-2-code': 'SM',
  963. 'alpha-3-code': 'SMR',
  964. 'continent': 'Europe',
  965. 'name': 'San Marino',
  966. 'capital': 'San Marino'},
  967. {'timezones': ['Africa/Dakar'],
  968. 'alpha-2-code': 'SN',
  969. 'alpha-3-code': 'SEN',
  970. 'continent': 'Africa',
  971. 'name': 'Senegal',
  972. 'capital': 'Dakar'},
  973. {'timezones': ['Africa/Mogadishu'],
  974. 'alpha-2-code': 'SO',
  975. 'alpha-3-code': 'SOM',
  976. 'continent': 'Africa',
  977. 'name': 'Somalia',
  978. 'capital': 'Mogadishu'},
  979. {'timezones': ['America/Paramaribo'],
  980. 'alpha-2-code': 'SR',
  981. 'alpha-3-code': 'SUR',
  982. 'continent': 'South America',
  983. 'name': 'Suriname',
  984. 'capital': 'Paramaribo'},
  985. {'timezones': ['Africa/Sao_Tome'],
  986. 'alpha-2-code': 'ST',
  987. 'alpha-3-code': 'STP',
  988. 'continent': 'Africa',
  989. 'name': 'S\xc3\xa3o Tom\xc3\xa9 and Pr\xc3\xadncipe',
  990. 'capital': 'S\xc3\xa3o Tom\xc3\xa9'},
  991. {'timezones': ['Asia/Damascus'],
  992. 'alpha-2-code': 'SY',
  993. 'alpha-3-code': 'SYR',
  994. 'continent': 'Asia',
  995. 'name': 'Syria',
  996. 'capital': 'Damascus'},
  997. {'timezones': ['Africa/Lome'],
  998. 'alpha-2-code': 'TG',
  999. 'alpha-3-code': 'TGO',
  1000. 'continent': 'Africa',
  1001. 'name': 'Togo',
  1002. 'capital': 'Lom\xc3\xa9'},
  1003. {'timezones': ['Asia/Bangkok'],
  1004. 'alpha-2-code': 'TH',
  1005. 'alpha-3-code': 'THA',
  1006. 'continent': 'Asia',
  1007. 'name': 'Thailand',
  1008. 'capital': 'Bangkok'},
  1009. {'timezones': ['Asia/Dushanbe'],
  1010. 'alpha-2-code': 'TJ',
  1011. 'alpha-3-code': 'TJK',
  1012. 'continent': 'Asia',
  1013. 'name': 'Tajikistan',
  1014. 'capital': 'Dushanbe'},
  1015. {'timezones': ['Asia/Ashgabat'],
  1016. 'alpha-2-code': 'TM',
  1017. 'alpha-3-code': 'TKM',
  1018. 'continent': 'Asia',
  1019. 'name': 'Turkmenistan',
  1020. 'capital': 'Ashgabat'},
  1021. {'timezones': ['Africa/Tunis'],
  1022. 'alpha-2-code': 'TN',
  1023. 'alpha-3-code': 'TUN',
  1024. 'continent': 'Africa',
  1025. 'name': 'Tunisia',
  1026. 'capital': 'Tunis'},
  1027. {'timezones': ['Pacific/Tongatapu'],
  1028. 'alpha-2-code': 'TO',
  1029. 'alpha-3-code': 'TON',
  1030. 'continent': 'Oceania',
  1031. 'name': 'Tonga',
  1032. 'capital': 'Nuku\xca\xbbalofa'},
  1033. {'timezones': ['Europe/Istanbul'],
  1034. 'alpha-2-code': 'TR',
  1035. 'alpha-3-code': 'TUR',
  1036. 'continent': 'Asia',
  1037. 'name': 'Turkey',
  1038. 'capital': 'Ankara'},
  1039. {'timezones': ['America/Port_of_Spain'],
  1040. 'alpha-2-code': 'TT',
  1041. 'alpha-3-code': 'TTO',
  1042. 'continent': 'North America',
  1043. 'name': 'Trinidad and Tobago',
  1044. 'capital': 'Port of Spain'},
  1045. {'timezones': ['Pacific/Funafuti'],
  1046. 'alpha-2-code': 'TV',
  1047. 'alpha-3-code': 'TUV',
  1048. 'continent': 'Oceania',
  1049. 'name': 'Tuvalu',
  1050. 'capital': 'Funafuti'},
  1051. {'timezones': ['Africa/Dar_es_Salaam'],
  1052. 'alpha-2-code': 'TZ',
  1053. 'alpha-3-code': 'TZA',
  1054. 'continent': 'Africa',
  1055. 'name': 'Tanzania',
  1056. 'capital': 'Dodoma'},
  1057. {'timezones': ['Europe/Kiev',
  1058. 'Europe/Uzhgorod',
  1059. 'Europe/Zaporozhye',
  1060. 'Europe/Simferopol'],
  1061. 'alpha-2-code': 'UA',
  1062. 'alpha-3-code': 'UKR',
  1063. 'continent': 'Europe',
  1064. 'name': 'Ukraine',
  1065. 'capital': 'Kiev'},
  1066. {'timezones': ['Africa/Kampala'],
  1067. 'alpha-2-code': 'UG',
  1068. 'alpha-3-code': 'UGA',
  1069. 'continent': 'Africa',
  1070. 'name': 'Uganda',
  1071. 'capital': 'Kampala'},
  1072. {'timezones': ['America/New_York',
  1073. 'America/Detroit',
  1074. 'America/Kentucky/Louisville',
  1075. 'America/Kentucky/Monticello',
  1076. 'America/Indiana/Indianapolis',
  1077. 'America/Indiana/Marengo',
  1078. 'America/Indiana/Knox',
  1079. 'America/Indiana/Vevay',
  1080. 'America/Chicago',
  1081. 'America/Indiana/Vincennes',
  1082. 'America/Indiana/Petersburg',
  1083. 'America/Menominee',
  1084. 'America/North_Dakota/Center',
  1085. 'America/North_Dakota/New_Salem',
  1086. 'America/Denver',
  1087. 'America/Boise',
  1088. 'America/Shiprock',
  1089. 'America/Phoenix',
  1090. 'America/Los_Angeles',
  1091. 'America/Anchorage',
  1092. 'America/Juneau',
  1093. 'America/Yakutat',
  1094. 'America/Nome',
  1095. 'America/Adak',
  1096. 'Pacific/Honolulu'],
  1097. 'alpha-2-code': 'US',
  1098. 'alpha-3-code': 'USA',
  1099. 'continent': 'North America',
  1100. 'name': 'United States',
  1101. 'capital': 'Washington, D.C.'},
  1102. {'timezones': ['America/Montevideo'],
  1103. 'alpha-2-code': 'UY',
  1104. 'alpha-3-code': 'URY',
  1105. 'continent': 'South America',
  1106. 'name': 'Uruguay',
  1107. 'capital': 'Montevideo'},
  1108. {'timezones': ['Asia/Samarkand',
  1109. 'Asia/Tashkent'],
  1110. 'alpha-2-code': 'UZ',
  1111. 'alpha-3-code': 'UZB',
  1112. 'continent': 'Asia',
  1113. 'name': 'Uzbekistan',
  1114. 'capital': 'Tashkent'},
  1115. {'timezones': ['Europe/Vatican'],
  1116. 'alpha-2-code': 'VA',
  1117. 'alpha-3-code': 'VAT',
  1118. 'continent': 'Europe',
  1119. 'name': 'Vatican City',
  1120. 'capital': 'Vatican City'},
  1121. {'timezones': ['America/Caracas'],
  1122. 'alpha-2-code': 'VE',
  1123. 'alpha-3-code': 'VEN',
  1124. 'continent': 'South America',
  1125. 'name': 'Venezuela',
  1126. 'capital': 'Caracas'},
  1127. {'timezones': ['Asia/Saigon'],
  1128. 'alpha-2-code': 'VN',
  1129. 'alpha-3-code': 'VNM',
  1130. 'continent': 'Asia',
  1131. 'name': 'Vietnam',
  1132. 'capital': 'Hanoi'},
  1133. {'timezones': ['Pacific/Efate'],
  1134. 'alpha-2-code': 'VU',
  1135. 'alpha-3-code': 'VUT',
  1136. 'continent': 'Oceania',
  1137. 'name': 'Vanuatu',
  1138. 'capital': 'Port Vila'},
  1139. {'timezones': ['Asia/Aden'],
  1140. 'alpha-2-code': 'YE',
  1141. 'alpha-3-code': 'YEM',
  1142. 'continent': 'Asia',
  1143. 'name': 'Yemen',
  1144. 'capital': "Sana'a"},
  1145. {'timezones': ['Africa/Lusaka'],
  1146. 'alpha-2-code': 'ZM',
  1147. 'alpha-3-code': 'ZMB',
  1148. 'continent': 'Africa',
  1149. 'name': 'Zambia',
  1150. 'capital': 'Lusaka'},
  1151. {'timezones': ['Africa/Harare'],
  1152. 'alpha-2-code': 'ZW',
  1153. 'alpha-3-code': 'ZWE',
  1154. 'continent': 'Africa',
  1155. 'name': 'Zimbabwe',
  1156. 'capital': 'Harare'},
  1157. {'timezones': ['Africa/Algiers'],
  1158. 'alpha-2-code': 'DZ',
  1159. 'alpha-3-code': 'DZA',
  1160. 'continent': 'Africa',
  1161. 'name': 'Algeria',
  1162. 'capital': 'Algiers'},
  1163. {'timezones': ['Europe/Sarajevo'],
  1164. 'alpha-2-code': 'BA',
  1165. 'alpha-3-code': 'BIH',
  1166. 'continent': 'Europe',
  1167. 'name': 'Bosnia and Herzegovina',
  1168. 'capital': 'Sarajevo'},
  1169. {'timezones': ['Asia/Phnom_Penh'],
  1170. 'alpha-2-code': 'KH',
  1171. 'alpha-3-code': 'KHM',
  1172. 'continent': 'Asia',
  1173. 'name': 'Cambodia',
  1174. 'capital': 'Phnom Penh'},
  1175. {'timezones': ['Africa/Bangui'],
  1176. 'alpha-2-code': 'CF',
  1177. 'alpha-3-code': 'CAF',
  1178. 'continent': 'Africa',
  1179. 'name': 'Central African Republic',
  1180. 'capital': 'Bangui'},
  1181. {'timezones': ['Africa/Ndjamena'],
  1182. 'alpha-2-code': 'TD',
  1183. 'alpha-3-code': 'TCD',
  1184. 'continent': 'Africa',
  1185. 'name': 'Chad',
  1186. 'capital': "N'Djamena"},
  1187. {'timezones': ['Indian/Comoro'],
  1188. 'alpha-2-code': 'KM',
  1189. 'alpha-3-code': 'COM',
  1190. 'continent': 'Africa',
  1191. 'name': 'Comoros',
  1192. 'capital': 'Moroni'},
  1193. {'timezones': ['Europe/Zagreb'],
  1194. 'alpha-2-code': 'HR',
  1195. 'alpha-3-code': 'HRV',
  1196. 'continent': 'Europe',
  1197. 'name': 'Croatia',
  1198. 'capital': 'Zagreb'},
  1199. {'timezones': ['Asia/Dili'],
  1200. 'alpha-2-code': 'TL',
  1201. 'alpha-3-code': 'TLS',
  1202. 'continent': 'Asia',
  1203. 'name': 'East Timor',
  1204. 'capital': 'Dili'},
  1205. {'timezones': ['America/El_Salvador'],
  1206. 'alpha-2-code': 'SV',
  1207. 'alpha-3-code': 'SLV',
  1208. 'continent': 'North America',
  1209. 'name': 'El Salvador',
  1210. 'capital': 'San Salvador'},
  1211. {'timezones': ['Africa/Malabo'],
  1212. 'alpha-2-code': 'GQ',
  1213. 'alpha-3-code': 'GNQ',
  1214. 'continent': 'Africa',
  1215. 'name': 'Equatorial Guinea',
  1216. 'capital': 'Malabo'},
  1217. {'timezones': ['America/Grenada'],
  1218. 'alpha-2-code': 'GD',
  1219. 'alpha-3-code': 'GRD',
  1220. 'continent': 'North America',
  1221. 'name': 'Grenada',
  1222. 'capital': "St. George's"},
  1223. {'timezones': ['Asia/Almaty',
  1224. 'Asia/Qyzylorda',
  1225. 'Asia/Aqtobe',
  1226. 'Asia/Aqtau',
  1227. 'Asia/Oral'],
  1228. 'alpha-2-code': 'KZ',
  1229. 'alpha-3-code': 'KAZ',
  1230. 'continent': 'Asia',
  1231. 'name': 'Kazakhstan',
  1232. 'capital': 'Astana'},
  1233. {'timezones': ['Asia/Vientiane'],
  1234. 'alpha-2-code': 'LA',
  1235. 'alpha-3-code': 'LAO',
  1236. 'continent': 'Asia',
  1237. 'name': 'Laos',
  1238. 'capital': 'Vientiane'},
  1239. {'timezones': ['Pacific/Truk',
  1240. 'Pacific/Ponape',
  1241. 'Pacific/Kosrae'],
  1242. 'alpha-2-code': 'FM',
  1243. 'alpha-3-code': 'FSM',
  1244. 'continent': 'Oceania',
  1245. 'name': 'Federated States of Micronesia',
  1246. 'capital': 'Palikir'},
  1247. {'timezones': ['Europe/Chisinau'],
  1248. 'alpha-2-code': 'MD',
  1249. 'alpha-3-code': 'MDA',
  1250. 'continent': 'Europe',
  1251. 'name': 'Moldova',
  1252. 'capital': 'Chi\xc5\x9fin\xc4\x83u'},
  1253. {'timezones': ['Europe/Monaco'],
  1254. 'alpha-2-code': 'MC',
  1255. 'alpha-3-code': 'MCO',
  1256. 'continent': 'Europe',
  1257. 'name': 'Monaco',
  1258. 'capital': 'Monaco'},
  1259. {'timezones': ['Europe/Podgorica'],
  1260. 'alpha-2-code': 'ME',
  1261. 'alpha-3-code': 'MNE',
  1262. 'continent': 'Europe',
  1263. 'name': 'Montenegro',
  1264. 'capital': 'Podgorica'},
  1265. {'timezones': ['Africa/Casablanca'],
  1266. 'alpha-2-code': 'MA',
  1267. 'alpha-3-code': 'MAR',
  1268. 'continent': 'Africa',
  1269. 'name': 'Morocco',
  1270. 'capital': 'Rabat'},
  1271. {'timezones': ['America/St_Kitts'],
  1272. 'alpha-2-code': 'KN',
  1273. 'alpha-3-code': 'KNA',
  1274. 'continent': 'North America',
  1275. 'name': 'Saint Kitts and Nevis',
  1276. 'capital': 'Basseterre'},
  1277. {'timezones': ['America/St_Lucia'],
  1278. 'alpha-2-code': 'LC',
  1279. 'alpha-3-code': 'LCA',
  1280. 'continent': 'North America',
  1281. 'name': 'Saint Lucia',
  1282. 'capital': 'Castries'},
  1283. {'timezones': ['America/St_Vincent'],
  1284. 'alpha-2-code': 'VC',
  1285. 'alpha-3-code': 'VCT',
  1286. 'continent': 'North America',
  1287. 'name': 'Saint Vincent and the Grenadines',
  1288. 'capital': 'Kingstown'},
  1289. {'timezones': ['Pacific/Apia'],
  1290. 'alpha-2-code': 'WS',
  1291. 'alpha-3-code': 'WSM',
  1292. 'continent': 'Oceania',
  1293. 'name': 'Samoa',
  1294. 'capital': 'Apia'},
  1295. {'timezones': ['Europe/Belgrade'],
  1296. 'alpha-2-code': 'RS',
  1297. 'alpha-3-code': 'SRB',
  1298. 'continent': 'Europe',
  1299. 'name': 'Serbia',
  1300. 'capital': 'Belgrade'},
  1301. {'timezones': ['Africa/Johannesburg'],
  1302. 'alpha-2-code': 'ZA',
  1303. 'alpha-3-code': 'ZAF',
  1304. 'continent': 'Africa',
  1305. 'name': 'South Africa',
  1306. 'capital': 'Pretoria'},
  1307. {'timezones': ['Europe/Madrid',
  1308. 'Africa/Ceuta',
  1309. 'Atlantic/Canary'],
  1310. 'alpha-2-code': 'ES',
  1311. 'alpha-3-code': 'ESP',
  1312. 'continent': 'Europe',
  1313. 'name': 'Spain',
  1314. 'capital': 'Madrid'},
  1315. {'timezones': ['Asia/Colombo'],
  1316. 'alpha-2-code': 'LK',
  1317. 'alpha-3-code': 'LKA',
  1318. 'continent': 'Asia',
  1319. 'name': 'Sri Lanka',
  1320. 'capital': 'Sri Jayewardenepura Kotte'},
  1321. {'timezones': ['Africa/Mbabane'],
  1322. 'alpha-2-code': 'SZ',
  1323. 'alpha-3-code': 'SWZ',
  1324. 'continent': 'Africa',
  1325. 'name': 'Swaziland',
  1326. 'capital': 'Mbabane'},
  1327. {'timezones': ['Europe/Zurich'],
  1328. 'alpha-2-code': 'CH',
  1329. 'alpha-3-code': 'CHE',
  1330. 'continent': 'Europe',
  1331. 'name': 'Switzerland',
  1332. 'capital': 'Bern'},
  1333. {'timezones': ['Asia/Dubai'],
  1334. 'alpha-2-code': 'AE',
  1335. 'alpha-3-code': 'ARE',
  1336. 'continent': 'Asia',
  1337. 'name': 'United Arab Emirates',
  1338. 'capital': 'Abu Dhabi'},
  1339. {'timezones': ['Europe/London'],
  1340. 'alpha-2-code': 'GB',
  1341. 'alpha-3-code': 'GBR',
  1342. 'continent': 'Europe',
  1343. 'name': 'United Kingdom',
  1344. 'capital': 'London'},
  1345. ]
  1346. regex = re.compile(timedelta_pattern)
  1347. def unix_time(self, end_datetime=None, start_datetime=None):
  1348. """
  1349. Get a timestamp between January 1, 1970 and now, unless passed
  1350. explicit start_datetime or end_datetime values.
  1351. :example 1061306726
  1352. """
  1353. start_datetime = self._parse_start_datetime(start_datetime)
  1354. end_datetime = self._parse_end_datetime(end_datetime)
  1355. return self.generator.random.randint(start_datetime, end_datetime)
  1356. def time_delta(self, end_datetime=None):
  1357. """
  1358. Get a timedelta object
  1359. """
  1360. end_datetime = self._parse_end_datetime(end_datetime)
  1361. ts = self.generator.random.randint(0, end_datetime)
  1362. return timedelta(seconds=ts)
  1363. def date_time(self, tzinfo=None, end_datetime=None):
  1364. """
  1365. Get a datetime object for a date between January 1, 1970 and now
  1366. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1367. :example DateTime('2005-08-16 20:39:21')
  1368. :return datetime
  1369. """
  1370. # NOTE: On windows, the lowest value you can get from windows is 86400
  1371. # on the first day. Known python issue:
  1372. # https://bugs.python.org/issue30684
  1373. return datetime(1970, 1, 1, tzinfo=tzinfo) + \
  1374. timedelta(seconds=self.unix_time(end_datetime=end_datetime))
  1375. def date_time_ad(self, tzinfo=None, end_datetime=None, start_datetime=None):
  1376. """
  1377. Get a datetime object for a date between January 1, 001 and now
  1378. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1379. :example DateTime('1265-03-22 21:15:52')
  1380. :return datetime
  1381. """
  1382. # 1970-01-01 00:00:00 UTC minus 62135596800 seconds is
  1383. # 0001-01-01 00:00:00 UTC. Since _parse_end_datetime() is used
  1384. # elsewhere where a default value of 0 is expected, we can't
  1385. # simply change that class method to use this magic number as a
  1386. # default value when None is provided.
  1387. start_time = -62135596800 if start_datetime is None else self._parse_start_datetime(start_datetime)
  1388. end_datetime = self._parse_end_datetime(end_datetime)
  1389. ts = self.generator.random.randint(start_time, end_datetime)
  1390. # NOTE: using datetime.fromtimestamp(ts) directly will raise
  1391. # a "ValueError: timestamp out of range for platform time_t"
  1392. # on some platforms due to system C functions;
  1393. # see http://stackoverflow.com/a/10588133/2315612
  1394. # NOTE: On windows, the lowest value you can get from windows is 86400
  1395. # on the first day. Known python issue:
  1396. # https://bugs.python.org/issue30684
  1397. return datetime(1970, 1, 1, tzinfo=tzinfo) + timedelta(seconds=ts)
  1398. def iso8601(self, tzinfo=None, end_datetime=None):
  1399. """
  1400. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1401. :example '2003-10-21T16:05:52+0000'
  1402. """
  1403. return self.date_time(tzinfo, end_datetime=end_datetime).isoformat()
  1404. def date(self, pattern='%Y-%m-%d', end_datetime=None):
  1405. """
  1406. Get a date string between January 1, 1970 and now
  1407. :param pattern format
  1408. :example '2008-11-27'
  1409. """
  1410. return self.date_time(end_datetime=end_datetime).strftime(pattern)
  1411. def date_object(self, end_datetime=None):
  1412. """
  1413. Get a date object between January 1, 1970 and now
  1414. :example datetime.date(2016, 9, 20)
  1415. """
  1416. return self.date_time(end_datetime=end_datetime).date()
  1417. def time(self, pattern='%H:%M:%S', end_datetime=None):
  1418. """
  1419. Get a time string (24h format by default)
  1420. :param pattern format
  1421. :example '15:02:34'
  1422. """
  1423. return self.date_time(
  1424. end_datetime=end_datetime).time().strftime(pattern)
  1425. def time_object(self, end_datetime=None):
  1426. """
  1427. Get a time object
  1428. :example datetime.time(15, 56, 56, 772876)
  1429. """
  1430. return self.date_time(end_datetime=end_datetime).time()
  1431. @classmethod
  1432. def _parse_start_datetime(cls, value):
  1433. if value is None:
  1434. return 0
  1435. return cls._parse_date_time(value)
  1436. @classmethod
  1437. def _parse_end_datetime(cls, value):
  1438. if value is None:
  1439. return int(time())
  1440. return cls._parse_date_time(value)
  1441. @classmethod
  1442. def _parse_date_string(cls, value):
  1443. parts = cls.regex.match(value)
  1444. if not parts:
  1445. raise ParseError("Can't parse date string `{}`.".format(value))
  1446. parts = parts.groupdict()
  1447. time_params = {}
  1448. for (name_, param_) in parts.items():
  1449. if param_:
  1450. time_params[name_] = int(param_)
  1451. if 'years' in time_params:
  1452. if 'days' not in time_params:
  1453. time_params['days'] = 0
  1454. time_params['days'] += 365.24 * time_params.pop('years')
  1455. if not time_params:
  1456. raise ParseError("Can't parse date string `{}`.".format(value))
  1457. return time_params
  1458. @classmethod
  1459. def _parse_timedelta(cls, value):
  1460. if isinstance(value, timedelta):
  1461. return value.total_seconds()
  1462. if is_string(value):
  1463. time_params = cls._parse_date_string(value)
  1464. return timedelta(**time_params).total_seconds()
  1465. if isinstance(value, (int, float)):
  1466. return value
  1467. raise ParseError("Invalid format for timedelta '{0}'".format(value))
  1468. @classmethod
  1469. def _parse_date_time(cls, text, tzinfo=None):
  1470. if isinstance(text, (datetime, date, real_datetime, real_date)):
  1471. return datetime_to_timestamp(text)
  1472. now = datetime.now(tzinfo)
  1473. if isinstance(text, timedelta):
  1474. return datetime_to_timestamp(now - text)
  1475. if is_string(text):
  1476. if text == 'now':
  1477. return datetime_to_timestamp(datetime.now(tzinfo))
  1478. time_params = cls._parse_date_string(text)
  1479. return datetime_to_timestamp(now + timedelta(**time_params))
  1480. if isinstance(text, int):
  1481. return datetime_to_timestamp(now + timedelta(text))
  1482. raise ParseError("Invalid format for date '{0}'".format(text))
  1483. @classmethod
  1484. def _parse_date(cls, value):
  1485. if isinstance(value, (datetime, real_datetime)):
  1486. return value.date()
  1487. elif isinstance(value, (date, real_date)):
  1488. return value
  1489. today = date.today()
  1490. if isinstance(value, timedelta):
  1491. return today - value
  1492. if is_string(value):
  1493. if value in ('today', 'now'):
  1494. return today
  1495. time_params = cls._parse_date_string(value)
  1496. return today + timedelta(**time_params)
  1497. if isinstance(value, int):
  1498. return today + timedelta(value)
  1499. raise ParseError("Invalid format for date '{0}'".format(value))
  1500. def date_time_between(self, start_date='-30y', end_date='now', tzinfo=None):
  1501. """
  1502. Get a DateTime object based on a random date between two given dates.
  1503. Accepts date strings that can be recognized by strtotime().
  1504. :param start_date Defaults to 30 years ago
  1505. :param end_date Defaults to "now"
  1506. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1507. :example DateTime('1999-02-02 11:42:52')
  1508. :return DateTime
  1509. """
  1510. start_date = self._parse_date_time(start_date, tzinfo=tzinfo)
  1511. end_date = self._parse_date_time(end_date, tzinfo=tzinfo)
  1512. if end_date - start_date <= 1:
  1513. ts = start_date + self.generator.random.random()
  1514. else:
  1515. ts = self.generator.random.randint(start_date, end_date)
  1516. if tzinfo is None:
  1517. return datetime(1970, 1, 1, tzinfo=tzinfo) + timedelta(seconds=ts)
  1518. else:
  1519. return (
  1520. datetime(1970, 1, 1, tzinfo=tzutc()) + timedelta(seconds=ts)
  1521. ).astimezone(tzinfo)
  1522. def date_between(self, start_date='-30y', end_date='today'):
  1523. """
  1524. Get a Date object based on a random date between two given dates.
  1525. Accepts date strings that can be recognized by strtotime().
  1526. :param start_date Defaults to 30 years ago
  1527. :param end_date Defaults to "today"
  1528. :example Date('1999-02-02')
  1529. :return Date
  1530. """
  1531. start_date = self._parse_date(start_date)
  1532. end_date = self._parse_date(end_date)
  1533. return self.date_between_dates(date_start=start_date, date_end=end_date)
  1534. def future_datetime(self, end_date='+30d', tzinfo=None):
  1535. """
  1536. Get a DateTime object based on a random date between 1 second form now
  1537. and a given date.
  1538. Accepts date strings that can be recognized by strtotime().
  1539. :param end_date Defaults to "+30d"
  1540. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1541. :example DateTime('1999-02-02 11:42:52')
  1542. :return DateTime
  1543. """
  1544. return self.date_time_between(
  1545. start_date='+1s', end_date=end_date, tzinfo=tzinfo,
  1546. )
  1547. def future_date(self, end_date='+30d', tzinfo=None):
  1548. """
  1549. Get a Date object based on a random date between 1 day from now and a
  1550. given date.
  1551. Accepts date strings that can be recognized by strtotime().
  1552. :param end_date Defaults to "+30d"
  1553. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1554. :example DateTime('1999-02-02 11:42:52')
  1555. :return DateTime
  1556. """
  1557. return self.date_between(start_date='+1d', end_date=end_date)
  1558. def past_datetime(self, start_date='-30d', tzinfo=None):
  1559. """
  1560. Get a DateTime object based on a random date between a given date and 1
  1561. second ago.
  1562. Accepts date strings that can be recognized by strtotime().
  1563. :param start_date Defaults to "-30d"
  1564. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1565. :example DateTime('1999-02-02 11:42:52')
  1566. :return DateTime
  1567. """
  1568. return self.date_time_between(
  1569. start_date=start_date, end_date='-1s', tzinfo=tzinfo,
  1570. )
  1571. def past_date(self, start_date='-30d', tzinfo=None):
  1572. """
  1573. Get a Date object based on a random date between a given date and 1 day
  1574. ago.
  1575. Accepts date strings that can be recognized by strtotime().
  1576. :param start_date Defaults to "-30d"
  1577. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1578. :example DateTime('1999-02-02 11:42:52')
  1579. :return DateTime
  1580. """
  1581. return self.date_between(start_date=start_date, end_date='-1d')
  1582. def date_time_between_dates(
  1583. self,
  1584. datetime_start=None,
  1585. datetime_end=None,
  1586. tzinfo=None):
  1587. """
  1588. Takes two DateTime objects and returns a random datetime between the two
  1589. given datetimes.
  1590. Accepts DateTime objects.
  1591. :param datetime_start: DateTime
  1592. :param datetime_end: DateTime
  1593. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1594. :example DateTime('1999-02-02 11:42:52')
  1595. :return DateTime
  1596. """
  1597. if datetime_start is None:
  1598. datetime_start = datetime.now(tzinfo)
  1599. if datetime_end is None:
  1600. datetime_end = datetime.now(tzinfo)
  1601. timestamp = self.generator.random.randint(
  1602. datetime_to_timestamp(datetime_start),
  1603. datetime_to_timestamp(datetime_end),
  1604. )
  1605. if tzinfo is None:
  1606. pick = datetime.fromtimestamp(timestamp, tzlocal())
  1607. pick = pick.astimezone(tzutc()).replace(tzinfo=None)
  1608. else:
  1609. pick = datetime.fromtimestamp(timestamp, tzinfo)
  1610. return pick
  1611. def date_between_dates(self, date_start=None, date_end=None):
  1612. """
  1613. Takes two Date objects and returns a random date between the two given dates.
  1614. Accepts Date or Datetime objects
  1615. :param date_start: Date
  1616. :param date_end: Date
  1617. :return Date
  1618. """
  1619. return self.date_time_between_dates(date_start, date_end).date()
  1620. def date_time_this_century(
  1621. self,
  1622. before_now=True,
  1623. after_now=False,
  1624. tzinfo=None):
  1625. """
  1626. Gets a DateTime object for the current century.
  1627. :param before_now: include days in current century before today
  1628. :param after_now: include days in current century after today
  1629. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1630. :example DateTime('2012-04-04 11:02:02')
  1631. :return DateTime
  1632. """
  1633. now = datetime.now(tzinfo)
  1634. this_century_start = datetime(
  1635. now.year - (now.year % 100), 1, 1, tzinfo=tzinfo)
  1636. next_century_start = datetime(
  1637. min(this_century_start.year + 100, MAXYEAR), 1, 1, tzinfo=tzinfo)
  1638. if before_now and after_now:
  1639. return self.date_time_between_dates(
  1640. this_century_start, next_century_start, tzinfo)
  1641. elif not before_now and after_now:
  1642. return self.date_time_between_dates(now, next_century_start, tzinfo)
  1643. elif not after_now and before_now:
  1644. return self.date_time_between_dates(this_century_start, now, tzinfo)
  1645. else:
  1646. return now
  1647. def date_time_this_decade(
  1648. self,
  1649. before_now=True,
  1650. after_now=False,
  1651. tzinfo=None):
  1652. """
  1653. Gets a DateTime object for the decade year.
  1654. :param before_now: include days in current decade before today
  1655. :param after_now: include days in current decade after today
  1656. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1657. :example DateTime('2012-04-04 11:02:02')
  1658. :return DateTime
  1659. """
  1660. now = datetime.now(tzinfo)
  1661. this_decade_start = datetime(
  1662. now.year - (now.year % 10), 1, 1, tzinfo=tzinfo)
  1663. next_decade_start = datetime(
  1664. min(this_decade_start.year + 10, MAXYEAR), 1, 1, tzinfo=tzinfo)
  1665. if before_now and after_now:
  1666. return self.date_time_between_dates(
  1667. this_decade_start, next_decade_start, tzinfo)
  1668. elif not before_now and after_now:
  1669. return self.date_time_between_dates(now, next_decade_start, tzinfo)
  1670. elif not after_now and before_now:
  1671. return self.date_time_between_dates(this_decade_start, now, tzinfo)
  1672. else:
  1673. return now
  1674. def date_time_this_year(
  1675. self,
  1676. before_now=True,
  1677. after_now=False,
  1678. tzinfo=None):
  1679. """
  1680. Gets a DateTime object for the current year.
  1681. :param before_now: include days in current year before today
  1682. :param after_now: include days in current year after today
  1683. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1684. :example DateTime('2012-04-04 11:02:02')
  1685. :return DateTime
  1686. """
  1687. now = datetime.now(tzinfo)
  1688. this_year_start = now.replace(
  1689. month=1, day=1, hour=0, minute=0, second=0, microsecond=0)
  1690. next_year_start = datetime(now.year + 1, 1, 1, tzinfo=tzinfo)
  1691. if before_now and after_now:
  1692. return self.date_time_between_dates(
  1693. this_year_start, next_year_start, tzinfo)
  1694. elif not before_now and after_now:
  1695. return self.date_time_between_dates(now, next_year_start, tzinfo)
  1696. elif not after_now and before_now:
  1697. return self.date_time_between_dates(this_year_start, now, tzinfo)
  1698. else:
  1699. return now
  1700. def date_time_this_month(
  1701. self,
  1702. before_now=True,
  1703. after_now=False,
  1704. tzinfo=None):
  1705. """
  1706. Gets a DateTime object for the current month.
  1707. :param before_now: include days in current month before today
  1708. :param after_now: include days in current month after today
  1709. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1710. :example DateTime('2012-04-04 11:02:02')
  1711. :return DateTime
  1712. """
  1713. now = datetime.now(tzinfo)
  1714. this_month_start = now.replace(
  1715. day=1, hour=0, minute=0, second=0, microsecond=0)
  1716. next_month_start = this_month_start + \
  1717. relativedelta.relativedelta(months=1)
  1718. if before_now and after_now:
  1719. return self.date_time_between_dates(
  1720. this_month_start, next_month_start, tzinfo)
  1721. elif not before_now and after_now:
  1722. return self.date_time_between_dates(now, next_month_start, tzinfo)
  1723. elif not after_now and before_now:
  1724. return self.date_time_between_dates(this_month_start, now, tzinfo)
  1725. else:
  1726. return now
  1727. def date_this_century(self, before_today=True, after_today=False):
  1728. """
  1729. Gets a Date object for the current century.
  1730. :param before_today: include days in current century before today
  1731. :param after_today: include days in current century after today
  1732. :example Date('2012-04-04')
  1733. :return Date
  1734. """
  1735. today = date.today()
  1736. this_century_start = date(today.year - (today.year % 100), 1, 1)
  1737. next_century_start = date(this_century_start.year + 100, 1, 1)
  1738. if before_today and after_today:
  1739. return self.date_between_dates(
  1740. this_century_start, next_century_start)
  1741. elif not before_today and after_today:
  1742. return self.date_between_dates(today, next_century_start)
  1743. elif not after_today and before_today:
  1744. return self.date_between_dates(this_century_start, today)
  1745. else:
  1746. return today
  1747. def date_this_decade(self, before_today=True, after_today=False):
  1748. """
  1749. Gets a Date object for the decade year.
  1750. :param before_today: include days in current decade before today
  1751. :param after_today: include days in current decade after today
  1752. :example Date('2012-04-04')
  1753. :return Date
  1754. """
  1755. today = date.today()
  1756. this_decade_start = date(today.year - (today.year % 10), 1, 1)
  1757. next_decade_start = date(this_decade_start.year + 10, 1, 1)
  1758. if before_today and after_today:
  1759. return self.date_between_dates(this_decade_start, next_decade_start)
  1760. elif not before_today and after_today:
  1761. return self.date_between_dates(today, next_decade_start)
  1762. elif not after_today and before_today:
  1763. return self.date_between_dates(this_decade_start, today)
  1764. else:
  1765. return today
  1766. def date_this_year(self, before_today=True, after_today=False):
  1767. """
  1768. Gets a Date object for the current year.
  1769. :param before_today: include days in current year before today
  1770. :param after_today: include days in current year after today
  1771. :example Date('2012-04-04')
  1772. :return Date
  1773. """
  1774. today = date.today()
  1775. this_year_start = today.replace(month=1, day=1)
  1776. next_year_start = date(today.year + 1, 1, 1)
  1777. if before_today and after_today:
  1778. return self.date_between_dates(this_year_start, next_year_start)
  1779. elif not before_today and after_today:
  1780. return self.date_between_dates(today, next_year_start)
  1781. elif not after_today and before_today:
  1782. return self.date_between_dates(this_year_start, today)
  1783. else:
  1784. return today
  1785. def date_this_month(self, before_today=True, after_today=False):
  1786. """
  1787. Gets a Date object for the current month.
  1788. :param before_today: include days in current month before today
  1789. :param after_today: include days in current month after today
  1790. :param tzinfo: timezone, instance of datetime.tzinfo subclass
  1791. :example DateTime('2012-04-04 11:02:02')
  1792. :return DateTime
  1793. """
  1794. today = date.today()
  1795. this_month_start = today.replace(day=1)
  1796. next_month_start = this_month_start + \
  1797. relativedelta.relativedelta(months=1)
  1798. if before_today and after_today:
  1799. return self.date_between_dates(this_month_start, next_month_start)
  1800. elif not before_today and after_today:
  1801. return self.date_between_dates(today, next_month_start)
  1802. elif not after_today and before_today:
  1803. return self.date_between_dates(this_month_start, today)
  1804. else:
  1805. return today
  1806. def time_series(
  1807. self,
  1808. start_date='-30d',
  1809. end_date='now',
  1810. precision=None,
  1811. distrib=None,
  1812. tzinfo=None):
  1813. """
  1814. Returns a generator yielding tuples of ``(<datetime>, <value>)``.
  1815. The data points will start at ``start_date``, and be at every time interval specified by
  1816. ``precision``.
  1817. ``distrib`` is a callable that accepts ``<datetime>`` and returns ``<value>``
  1818. """
  1819. start_date = self._parse_date_time(start_date, tzinfo=tzinfo)
  1820. end_date = self._parse_date_time(end_date, tzinfo=tzinfo)
  1821. if end_date < start_date:
  1822. raise ValueError("`end_date` must be greater than `start_date`.")
  1823. if precision is None:
  1824. precision = (end_date - start_date) / 30
  1825. precision = self._parse_timedelta(precision)
  1826. if distrib is None:
  1827. def distrib(dt): return self.generator.random.uniform(0, precision) # noqa
  1828. if not callable(distrib):
  1829. raise ValueError(
  1830. "`distrib` must be a callable. Got {} instead.".format(distrib))
  1831. datapoint = start_date
  1832. while datapoint < end_date:
  1833. dt = timestamp_to_datetime(datapoint, tzinfo)
  1834. datapoint += precision
  1835. yield (dt, distrib(dt))
  1836. def am_pm(self):
  1837. return self.date('%p')
  1838. def day_of_month(self):
  1839. return self.date('%d')
  1840. def day_of_week(self):
  1841. return self.date('%A')
  1842. def month(self):
  1843. return self.date('%m')
  1844. def month_name(self):
  1845. return self.date('%B')
  1846. def year(self):
  1847. return self.date('%Y')
  1848. def century(self):
  1849. """
  1850. :example 'XVII'
  1851. """
  1852. return self.random_element(self.centuries)
  1853. def timezone(self):
  1854. return self.generator.random.choice(
  1855. self.random_element(self.countries)['timezones'])
  1856. def date_of_birth(self, tzinfo=None, minimum_age=0, maximum_age=115):
  1857. """
  1858. Generate a random date of birth represented as a Date object,
  1859. constrained by optional miminimum_age and maximum_age
  1860. parameters.
  1861. :param tzinfo Defaults to None.
  1862. :param minimum_age Defaults to 0.
  1863. :param maximum_age Defaults to 115.
  1864. :example Date('1979-02-02')
  1865. :return Date
  1866. """
  1867. if not isinstance(minimum_age, int):
  1868. raise TypeError("minimum_age must be an integer.")
  1869. if not isinstance(maximum_age, int):
  1870. raise TypeError("maximum_age must be an integer.")
  1871. if (maximum_age < 0):
  1872. raise ValueError("maximum_age must be greater than or equal to zero.")
  1873. if (minimum_age < 0):
  1874. raise ValueError("minimum_age must be greater than or equal to zero.")
  1875. if (minimum_age > maximum_age):
  1876. raise ValueError("minimum_age must be less than or equal to maximum_age.")
  1877. # In order to return the full range of possible dates of birth, add one
  1878. # year to the potential age cap and subtract one day if we land on the
  1879. # boundary.
  1880. now = datetime.now(tzinfo).date()
  1881. start_date = now.replace(year=now.year - (maximum_age+1))
  1882. end_date = now.replace(year=now.year - minimum_age)
  1883. dob = self.date_time_ad(tzinfo=tzinfo, start_datetime=start_date, end_datetime=end_date).date()
  1884. return dob if dob != start_date else dob + timedelta(days=1)