Completed
Push — master ( 410210...caabd8 )
by Oleksandr
01:07
created

il2fb.parsers.mission.to_time()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1
Metric Value
cc 1
dl 0
loc 4
ccs 4
cts 4
cp 1
crap 1
rs 10
1
# -*- coding: utf-8 -*-
2
3 1
import datetime
4 1
import math
5
6 1
from il2fb.commons import Skills, UnitTypes
7 1
from il2fb.commons.organization import AirForces, Belligerents
8
9 1
from .constants import NULL
10
11
12 1
def to_bool(value):
13
    """
14
    Converts a string representation of a number into boolean.
15
16
    :param str value: a string representation of a number to convert
17
18
    :returns: `False` if `value` is equal to `'0'`, `True` otherwise
19
    :rtype: :class:`bool`
20
21
    **Examples:**
22
23
    .. code-block:: python
24
25
       >>> to_bool('0')
26
       False
27
       >>> to_bool('1')
28
       True
29
       >>> to_bool('-1')
30
       True
31
    """
32 1
    return int(value) != 0
33
34
35 1
def to_belligerent(value):
36 1
    return Belligerents.get_by_value(int(value))
37
38
39 1
def to_skill(value):
40 1
    return Skills.get_by_value(int(value))
41
42
43 1
def to_unit_type(value):
44 1
    return UnitTypes.get_by_value(value.lower())
45
46
47 1
def to_air_force(value):
48 1
    if value == NULL:
49 1
        return AirForces.vvs_rkka
50 1
    elif value:
51 1
        return AirForces.get_by_value(value)
52
53
54 1
def to_time(value):
55 1
    time = float(value)
56 1
    minutes, hours = math.modf(time)
57
    return datetime.time(int(hours), int(minutes * 60))
58