Esempio n. 1
0
def test_seq_no_support_fmt():
    first = parse('20180105')
    last = parse('20180110')

    with pytest.raises(ValueError) as ex:
        seq.seqGen(first, last, 'd', 1, '%7')

    assert "Incorrect format string." == ex.value.args[0]
Esempio n. 2
0
def test_seq_no_support_unit():
    first = parse('20180105')
    last = parse('20180110')

    with pytest.raises(ValueError) as ex:
        seq.seqGen(first, last, 'z')

    assert "Incorrect unit. It should be 'h', 'd', or 'w'" == ex.value.args[0]
Esempio n. 3
0
def test_seq_days():
    first = parse('20180105')
    last = parse('20180107')
    actual = [d for d in seq.seqGen(first, last)]
    expected = ['20180105', '20180106', '20180107']

    assert actual == expected
Esempio n. 4
0
def test_seq_two_days():
    first = parse('20180105')
    last = parse('20180110')
    actual = [d for d in seq.seqGen(first, last, 'd', 2)]
    expected = ['20180105', '20180107', '20180109']

    assert actual == expected
Esempio n. 5
0
def test_seq_hours_fmt():
    first = parse('20180105-0900')
    last = parse('20180105-1100')
    actual = [d for d in seq.seqGen(first, last, 'h', 1, '%Y-%m-%d %H')]
    expected = ['2018-01-05 09', '2018-01-05 10', '2018-01-05 11']

    assert actual == expected
Esempio n. 6
0
def test_seq_hours():
    first = parse('20180105-0900')
    last = parse('20180105-1100')
    actual = [d for d in seq.seqGen(first, last, 'h', 1, '%Y%m%d-%H')]
    expected = ['20180105-09', '20180105-10', '20180105-11']

    assert actual == expected
Esempio n. 7
0
def main(args=None):
    """The main routine."""
    if args is None:
        args = sys.argv[1:]

    # Do argument parsing here (eg. with argparse) and anything else
    # you want your project to do.
    parser = argparse.ArgumentParser(description=description,
                                     formatter_class=RawTextHelpFormatter)
    parser.add_argument(
        'FIRST',
        metavar='FIRST',
        help=
        'first date of the seq. For example, 2018-05-01, 20180501, 20180501-0900, 2018-05-01T09:00'
    )
    parser.add_argument('LAST',
                        metavar='LAST',
                        help='last date of the seq. See also, FIRST')
    parser.add_argument('-i',
                        '--interval',
                        help='interval: h1, d1, w1. default value is d1')
    parser.add_argument('-f', '--format', help='see also, datetime.strftime')

    args = parser.parse_args()

    try:
        first = parse(args.FIRST)
        last = parse(args.LAST)
    except:
        print("invalid datetime format")
        sys.exit(1)

    fmt = DTS_DEFAULT_FORMAT
    if args.format:
        fmt = args.format

    unit = DTS_DEFAULT_UNIT
    how_long = DTS_DEFAULT_INTERVAL

    if args.interval and len(
            args.interval) >= 2 and args.interval[0] in DT_UNIT:
        unit = args.interval[0]
        how_long = int(args.interval[1:])

    try:
        hseq = seqGen(first, last, unit, how_long, fmt)
    except ValueError as ex:
        print(ex)
        return

    for d in hseq:
        print(d)