samedi 24 octobre 2015

Refactor random datetime on Python

I accept suggestions to improve this code

http://ift.tt/1O0pQ22

import random
import datetime

def gen_timestamp(min_year=1915, max_year=1996):
    # gera um datetime no formato yyyy-mm-dd hh:mm:ss.000000
    year = random.randint(min_year, max_year)
    month = random.randint(11, 12)
    day = random.randint(1, 28)
    hour = random.randint(1, 23)
    minute = random.randint(1, 59)
    second = random.randint(1, 59)
    microsecond = random.randint(1, 999999)
    date = datetime.datetime(
        year, month, day, hour, minute, second, microsecond).isoformat(" ")
    return date

Accept Pull Request

http://ift.tt/1Ntq4eY




Aucun commentaire:

Enregistrer un commentaire