Exemplo n.º 1
0
    private string getTimeLeft(ENUM_Actions action)
    {
        ulong lastAction    = 0;
        float secondsToWait = 0;

        switch (action)
        {
        case ENUM_Actions.PLAY:
            lastAction    = _lastPlayAction;
            secondsToWait = _playSecondsToWait;
            break;

        case ENUM_Actions.SHOWER:
            lastAction    = _lastShowerAction;
            secondsToWait = _showerSecondsToWait;
            break;

        case ENUM_Actions.EAT:
            lastAction    = _lastEatAction;
            secondsToWait = _eatSecondsToWait;
            break;
        }

        //timer
        ulong diff        = ((ulong)System.DateTime.Now.Ticks - lastAction);
        ulong miliseconds = diff / System.TimeSpan.TicksPerMillisecond;
        float secondsLeft = (float)((secondsToWait * 1000) - miliseconds) / 1000;

        string timer = "";

        bool isHours = false;

        //Hours
        timer += ((int)secondsLeft / 3600).ToString() + "H ";
        if (((int)secondsLeft / 3600) > 0)
        {
            isHours = true;
            timer   = ((int)secondsLeft / 3600).ToString() + "H";
        }
        secondsLeft -= ((int)secondsLeft / 3600) * 3600;
        //minutes
        //timer += ((int)secondsLeft / 60).ToString("00") + "M ";
        //seconds
        //timer += (secondsLeft % 60).ToString("00") + "S";

        if (!isHours)
        {
            timer = (secondsLeft % 60).ToString("00") + "S";

            if (((int)secondsLeft / 60) > 0)
            {
                timer = ((int)secondsLeft / 60).ToString("00") + "M";
            }
        }


        return(timer);
    }
Exemplo n.º 2
0
    private float getSecondsLeft(ENUM_Actions action)
    {
        ulong lastAction    = 0;
        float secondsToWait = 0;

        switch (action)
        {
        case ENUM_Actions.PLAY:
            lastAction    = _lastPlayAction;
            secondsToWait = _playSecondsToWait;
            break;

        case ENUM_Actions.SHOWER:
            lastAction    = _lastShowerAction;
            secondsToWait = _showerSecondsToWait;
            break;

        case ENUM_Actions.EAT:
            lastAction    = _lastEatAction;
            secondsToWait = _eatSecondsToWait;
            break;
        }

        //timer
        ulong diff        = ((ulong)System.DateTime.Now.Ticks - lastAction);
        ulong miliseconds = diff / System.TimeSpan.TicksPerMillisecond;
        float secondsLeft = (float)((secondsToWait * 1000) - miliseconds) / 1000;

        float extraSeconds = 0;

        //Hours check
        if (((int)secondsLeft / 3600) > 0)
        {
            extraSeconds = 3600 * ((int)secondsLeft / 3600);
        }
        secondsLeft -= (((int)secondsLeft / 3600) * 3600);
        secondsLeft += extraSeconds;
        return(secondsLeft);
    }