Ignore:
Timestamp:
1999-07-21T17:00:00+12:00 (25 years ago)
Author:
sjboddie
Message:

added some date formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/formattools.cpp

    r407 r410  
    1212/*
    1313   $Log$
     14   Revision 1.5  1999/07/21 05:00:00  sjboddie
     15   added some date formatting
     16
    1417   Revision 1.4  1999/07/20 03:02:15  sjboddie
    1518   added an [icon] option, added ability to call get_formatted_string
     
    3437
    3538
    36 
    37 
    38 
    3939// a few function prototypes
    4040static text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr,
     
    4545              text_tmap &metamap, int &metacount);
    4646
    47 
    48 
    4947void metadata_t::clear() {
     48  metaname.clear();
    5049  metaindex = 0;
    5150  parentcommand = pNone;
     
    5857  meta.clear();
    5958};
    60 
    6159
    6260void format_t::clear() {
     
    7169};
    7270
    73 
    74 
     71// returns a date of form _textmonthnn_ 31, 1999
     72// input is date of type 19991231
     73// at least the year must be present in date
     74static text_t format_date (const text_t &date) {
     75
     76  if (date.size() < 4) return "";
     77
     78  text_t::const_iterator datebegin = date.begin();
     79
     80  text_t year = substr (datebegin, datebegin+4);
     81
     82  if (date.size() < 6) return year;
     83
     84  text_t month = "_textmonth" + substr (datebegin+4, datebegin+6) + "_";
     85  int imonth = month.getint();
     86  if (imonth < 0 || imonth > 12) return year;
     87
     88  if (date.size() < 8) return month + ", " + year;
     89
     90  text_t day = substr (datebegin+6, datebegin+8);
     91  if (day[0] == '0') day = substr (day.begin()+1, day.end());
     92  int iday = day.getint();
     93  if (iday < 0 || iday > 31) return month + ", " + year;
     94   
     95  return month + " " + day + ", " + year;
     96
    7597
    7698static void get_parent_options (text_t &instring, metadata_t &metaoption) {
     
    145167  else {
    146168    formatlistptr->command = comMeta;
     169    formatlistptr->meta.metaname = meta;
    147170    if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
    148171      getParents = true;
     
    153176    text_tmap::const_iterator it;
    154177    if ((it = metamap.find(meta)) != metamap.end()) {
    155       (formatlistptr->meta).metaindex = (*it).second.getint();
     178      formatlistptr->meta.metaindex = (*it).second.getint();
    156179    } else {
    157180      metamap[meta] = count;
    158181      metadata.push_back (meta);
    159       (formatlistptr->meta).metaindex = count;
     182      formatlistptr->meta.metaindex = count;
    160183      count ++;
    161184    }
     
    347370
    348371
     372// note: all the format_date stuff is assuming that all Date metadata is going to
     373// be of the form yyyymmdd, this is of course, crap ;)
    349374
    350375static text_t get_meta (const ResultDocInfo_t &docinfo, const metadata_t &meta) {
     
    356381  switch (meta.parentcommand) {
    357382  case pNone:
     383    if (meta.metaname == "Date")
     384      return format_date (docinfo.metadata[mindex].values.back());
    358385    return docinfo.metadata[mindex].values.back();
    359386
    360387  case pImmediate:
    361     if (valuesize > 1)
     388    if (valuesize > 1) {
     389      if (meta.metaname == "Date")
     390    return format_date (docinfo.metadata[mindex].values[metasize-2]);
    362391      return docinfo.metadata[mindex].values[metasize-2];
     392    }
    363393    break;
    364394
    365395  case pTop:
    366     if (valuesize > 1)
     396    if (valuesize > 1) {
     397      if (meta.metaname == "Date")
     398    return format_date (docinfo.metadata[mindex].values[0]);
    367399      return docinfo.metadata[mindex].values[0];
     400    }
    368401    break;
    369402
    370403  case pIndex:
    371     if (valuesize > meta.parentindex)
     404    if (valuesize > meta.parentindex) {
     405      if (meta.metaname == "Date")
     406    return format_date (docinfo.metadata[mindex].values[meta.parentindex]);
    372407      return docinfo.metadata[mindex].values[meta.parentindex];
     408    }
    373409    break;
    374410
     
    383419      while (here != end) {
    384420    if (!first) tmp += meta.parentoptions;
    385     tmp += *here;
     421    if (meta.metaname == "Date") tmp += format_date (*here);
     422    else tmp += *here;
    386423    first = false;
    387424    here ++;
Note: See TracChangeset for help on using the changeset viewer.