Changeset 639 for cpp/frams


Ignore:
Timestamp:
12/05/16 02:29:50 (7 years ago)
Author:
Maciej Komosinski
Message:

Introduced separate functions for formatting time.

Location:
cpp/frams
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/genotypeloader.cpp

    r635 r639  
    1313        { "genotype", 0, 0, "Genotype", "s 1", FIELD(genotype), "Genes as a string of characters.", },
    1414
    15         { "info_timestamp", 1, 0, "Creation time", "fd 0 -1 0", FIELD(info_timestamp), },
     15        { "info_timestamp", 1, 0, "Last modified", "ft 0 -1 0", FIELD(info_timestamp), },
    1616        { "info_author", 1, 0, "Author name", "s 0 100", FIELD(info_author), },
    1717        { "info_author_ispublic", 1, 0, "Author name is public", "d 0 1 1", FIELD(info_author_ispublic), },
  • cpp/frams/util/extvalue.cpp

    r636 r639  
    746746}
    747747
    748 SString ExtValue::format(SString& fmt, const ExtValue **values, int count)
     748SString ExtValue::formatTime(char fmt, double value)
     749{
     750if (fmt=='i')
     751        { //could be Convert::ctime()
     752        int d,h,m,ti=value;
     753        int ms=1000*(value-ti);
     754        d=ti/86400; ti-=d*86400;
     755        h=ti/3600; ti-=h*3600;
     756        m=ti/60; ti-=m*60;
     757        SString ret;
     758        if (d>0) ret+=SString::sprintf("%dd ",d);
     759        if (h>0) ret+=SString::sprintf("%d:",h);
     760        ret+=SString::sprintf("%02d:%02d.%03d", m,ti,ms);
     761        return ret;
     762        }
     763time_t ti = value;
     764struct tm tm = Convert::localtime(ti);
     765switch(fmt)
     766        {
     767        case 'T': return SString::sprintf("%04d-%02d-%02d %02d:%02d:%02d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
     768        case 't': return SString(Convert::asctime(tm).c_str());
     769        case 'y': return SString::sprintf("%04d-%02d-%02d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday);
     770        case 'm': return SString::sprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, int(1000*(value-(double)ti)));
     771        }
     772return SString();
     773}
     774
     775SString ExtValue::format(const SString& fmt, const ExtValue **values, int count)
    749776{
    750777        SString ret;
     
    788815                                case 'f': case 'g': case 'e': type = 'f'; t = next; break;
    789816                                case 's': type = 's'; t = next; break;
    790                                 case 't': case 'T': type = *t; t = next; break;
     817                                case 't': case 'T': case 'y': case 'i': case 'm': type = *t; t = next; break;
    791818                                case '%': if (t > begin) { type = *t; t = next; } break;
    792819                        }
     
    805832                case 'f': a = args.getNext(); ret += SString::sprintf(sub.c_str(), a ? a->getDouble() : 0); break;
    806833                case 's': {a = args.getNext(); SString tmp; if (a) tmp = a->getString(); ret += SString::sprintf(sub.c_str(), tmp.c_str()); } break;
    807                 case 't': case 'T':
    808                 {
     834                case 't': case 'T': case 'i': case 'y': case 'm':
    809835                        a = args.getNext();
    810                         time_t ti = a ? a->getInt() : 0;
    811                         struct tm tm = Convert::localtime(ti);
    812                         SString timtxt;
    813                         if (type == 'T')
    814                                 timtxt = SString::sprintf("%04d-%02d-%02d %02d:%02d:%02d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
    815                         else
    816                                 timtxt = Convert::asctime(tm).c_str();
    817                         ret += timtxt;
     836                        ret += formatTime(type,a ? a->getDouble() : 0);
    818837                        ret += sub.substr(2);
    819                 }
    820838                        break;
    821839                case '%': ret += '%'; ret += sub.substr(2); break;
  • cpp/frams/util/extvalue.h

    r636 r639  
    219219        };
    220220
    221         static SString format(SString& fmt, const ExtValue **values, int count);
     221        static SString formatTime(char fmt, double value);
     222        static SString format(const SString& fmt, const ExtValue **values, int count);
    222223
    223224        ExtValue getExtType();
Note: See TracChangeset for help on using the changeset viewer.