File: CalcTime.py

package info (click to toggle)
sumo 0.28.0+dfsg1-1~bpo8+1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 103,616 kB
  • sloc: xml: 534,021; cpp: 183,697; python: 66,271; java: 43,017; ansic: 36,466; sh: 11,391; makefile: 1,411; perl: 450
file content (56 lines) | stat: -rw-r--r-- 1,744 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: Latin-1 -*-
"""
@file    CalcTime.py
@author  Sascha Krieg
@author  Daniel Krajzewicz
@author  Michael Behrisch
@date    2008-04-17
@version $Id: CalcTime.py 20433 2016-04-13 08:00:14Z behrisch $


SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
Copyright (C) 2008-2016 DLR (http://www.dlr.de/) and contributors

This file is part of SUMO.
SUMO is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
"""
from __future__ import absolute_import
from __future__ import print_function

from time import gmtime
from time import strftime
from time import strptime
from time import mktime
from time import localtime

format = "%Y-%m-%d %H:%M:%S"
formatTime = "%H:%M:%S"
# used simulation date in seconds
simDate = mktime((2007, 7, 18, 0, 0, 0, 2, 199, 1))


def getSecsInTime(time=85460):
    """calculates the Hour:Minutes:Seconds of the given time in seconds."""
    print(strftime(formatTime, gmtime(time)))


def getDateFromDepart(time):
    """calculates the Date from the departtime"""
    return strftime(format, localtime(simDate + int(time)))


def getTimeInSecs(date):
    """calculates the depart time in seconds of the given date (date should be same as simDate)"""
    result = (int)(mktime(strptime(date, format)) - simDate)
    if result < 0:
        print("WARNING: calculated time is negative")
    return result


def getNiceTimeLabel(label='20070718000020'):
    # returns 2007-07-18 00:00:20
    return label[:4] + "-" + label[4:6] + "-" + label[6:8] + " " + label[8:10] + ":" + label[10:12] + ":" + label[12:]