# all files / TypeScript.NET/source/System/Time/ TimeUnit.js

56% Statements 28/50
23.68% Branches 9/38
62.5% Functions 5/8
57.45% Lines 27/47

    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80

    1×
    1×
    1×

    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×
    1×
    1×
    1×
    5×
    5×

    5×

    1×
    1×

    1×
    1×

    1×
    1×

    1×

    1×
    1×
    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Originally based upon .NET source but with many additions and improvements.
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    (function (factory) {
        Eif (typeof module === 'object' && typeof module.exports === 'object') {
            var v = factory(require, exports); Iif (v !== undefined) module.exports = v;
        }
        else if (typeof define === 'function' && define.amd) {
            define(["require", "exports"], factory);
        }
    })(function (require, exports) {
        "use strict";
        (function (TimeUnit) {
            TimeUnit[TimeUnit["Ticks"] = 0] = "Ticks";
            TimeUnit[TimeUnit["Milliseconds"] = 1] = "Milliseconds";
            TimeUnit[TimeUnit["Seconds"] = 2] = "Seconds";
            TimeUnit[TimeUnit["Minutes"] = 3] = "Minutes";
            TimeUnit[TimeUnit["Hours"] = 4] = "Hours";
            TimeUnit[TimeUnit["Days"] = 5] = "Days";
        })(exports.TimeUnit || (exports.TimeUnit = {}));
        var TimeUnit = exports.TimeUnit;
        var TimeUnit;
        (function (TimeUnit) {
            function toMilliseconds(value, units) {
                Iif (units === void 0) { units = TimeUnit.Milliseconds; }
                switch (units) {
                    case TimeUnit.Days:
                        value *= 24;
                    case TimeUnit.Hours:
                        value *= 60;
                    case TimeUnit.Minutes:
                        value *= 60;
                    case TimeUnit.Seconds:
                        value *= 1000;
                    case TimeUnit.Milliseconds:
                        return value;
                    case TimeUnit.Ticks:
                        return value / 10000;
                    default:
                        throw new Error("Invalid TimeUnit.");
                }
            }
            TimeUnit.toMilliseconds = toMilliseconds;
            function fromMilliseconds(ms, units) {
                switch (units) {
                    case TimeUnit.Days:
                        return ms / 86400000;
                    case TimeUnit.Hours:
                        return ms / 3600000;
                    case TimeUnit.Minutes:
                        return ms / 60000;
                    case TimeUnit.Seconds:
                        return ms / 1000;
                    case TimeUnit.Milliseconds:
                        return ms;
                    case TimeUnit.Ticks:
                        return ms * 10000;
                    default:
                        throw new Error("Invalid TimeUnit.");
                }
            }
            TimeUnit.fromMilliseconds = fromMilliseconds;
            function from(quantity, unit) {
                return quantity && fromMilliseconds(quantity.getTotalMilliseconds(), unit);
            }
            TimeUnit.from = from;
            function assertValid(unit) {
                if (isNaN(unit) || unit > TimeUnit.Days || unit < TimeUnit.Ticks || Math.floor(unit) !== unit)
                    throw new Error("Invalid TimeUnit.");
                return true;
            }
            TimeUnit.assertValid = assertValid;
        })(TimeUnit = exports.TimeUnit || (exports.TimeUnit = {}));
        Object.freeze(TimeUnit);
        Object.defineProperty(exports, "__esModule", { value: true });
        exports.default = TimeUnit;
    });
    //# sourceMappingURL=TimeUnit.js.map