Example #1
0
long CL_TimeOfDay::ParseAndConvert (const CL_String& s)
{
    CL_String fld[4];
    short hour, min, sec;

    short n;
    if ((n = s.Split (fld, 4, ":")) == 2 || n == 3) {
        hour = (short) fld[0].AsLong ();
        min  = (short) fld[1].AsLong ();
        sec  = (short) fld[2].AsLong ();
    }
    else if (s.Split (fld, 4, ": ") == 3) {
        hour = (short) fld[0].AsLong ();
        min  = (short) fld[1].AsLong ();
        sec = 0;
        if (fld[2] == "pm")
            hour += 12;
    }
    else {
        // Assume that it's either four or six digits, and try to parse it.
        for (short i = 0; i < s.Size(); i++) {
            if (s[i] > '9' || s[i] < '0') {
                return -1;
            }
        }
        hour = (s[0]-'0')*10 + s[1]-'0';
        min  = (s[2]-'0')*10 + s[3]-'0';
        if (s.Size() == 6) {
            sec  = (s[4]-'0')*10 + s[5]-'0';
        }
        else
            sec = 0;
    }
    if (! (hour >= 0 && hour < 24) ) {
        return -1;
    }
    if (! (min >= 0 && min < 60) ) {
        return -1;
    }
    if (! (sec >= 0 && sec < 60) ) {
        return -1;
    }
    return (hour * 3600L + min * 60 + sec);
}    
Example #2
0
void CL_TimeOfDay::operator= (const CL_String& s)
{
    if (!PrepareToChange())
        return;
    if (s.Size() == 0) {
        _numSecs = 0;
        Notify ();
        return;
    }
    long l = ParseAndConvert (s);
    if (l < 0) {
        // CL_Error::Warning ("CL_TimeOfDay::op= (const CL_String&): "
        //                    "Invalid form '%s'", (char*) s);
        _numSecs = 0;
    }
    else
        _numSecs = l;
    Notify ();
}