Skip to content

Commit c03d69c

Browse files
committed
Extend \showdate with time possibilities
Extend the `\showdate` with the possibility to specify the time
1 parent 738fa3e commit c03d69c

File tree

3 files changed

+136
-16
lines changed

3 files changed

+136
-16
lines changed

doc/commands.doc

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,10 +1426,10 @@ contains \c TEST, or \c DEV
14261426
for an example.
14271427

14281428
<hr>
1429-
\section cmdshowdate \\showdate "<format>" [ <date> ]
1429+
\section cmdshowdate \\showdate "<format>" [ <date_time> ]
14301430

14311431
\addindex \\showdate
1432-
Shows the date based on the given \<format\> and \<date\>. Where the \<format\> is a string in which the following tokens have a special meaning:
1432+
Shows the date and time based on the given \<format\> and \<date_time\>. Where the \<format\> is a string in which the following tokens have a special meaning:
14331433
| Code | Description |
14341434
| :--- | :---------- |
14351435
| \%y | The last two decimal digits of the year. If the result is a single digit it is prefixed by 0.
@@ -1452,34 +1452,58 @@ contains \c TEST, or \c DEV
14521452
| \%A | The full weekday name.
14531453
| \%lA | As \%A but when not by default the case and when possible the first character is converted to uppercase.
14541454
| &nbsp; | &nbsp;
1455+
| \%H |The hour (0-23).
1456+
| \%0H | The hour (0-23). If the result is a single digit, it is prefixed with 0.
1457+
| \%I | The hour (0-11).
1458+
| \%0I | The hour (0-11). If the result is a single digit, it is prefixed with 0.
1459+
| \%M | The minute.
1460+
| \%0M | The minute. If the result is a single digit, it is prefixed with 0.
1461+
| \%S | The second.
1462+
| \%0S | The second. If the result is a single digit, it is prefixed with 0.
1463+
| &nbsp; | &nbsp;
14551464
| \%\% | A \% character.
14561465

14571466
Note that the \<format\> has to be between double quotes.
14581467

1459-
In case the \<date\> is specified it to has to have the following representation:
1460-
- one or 2 digits for the day
1461-
- a minus sign
1462-
- one or 2 digits for the month
1463-
- a minus sign
1464-
- 4 digits for the year
1468+
In case the \<date_time\> is specified it has to have the following representation:
1469+
- optional `date` where `date` is:
1470+
- one or 2 digits for the day
1471+
- a minus sign
1472+
- one or 2 digits for the month
1473+
- a minus sign
1474+
- 4 digits for the year
1475+
- optional `time` where `time` is:
1476+
- whitespace
1477+
- one or 2 digits for the hours
1478+
- a colon sign
1479+
- one or 2 digits for the minutes
1480+
- optionally
1481+
- a colon sign
1482+
- 2 digits for the seconds
14651483
.
1466-
in case the \<date\> is not specified the current date is used.
1484+
in case the \<date_time\> is not specified the current date and time are used.
14671485

14681486
Here is an example:
14691487
\code
14701488
- \showdate "%lA %0d-%0m-%Y" 14-3-2015
14711489
- \showdate "%a %d-%m-%y" 14-3-2015
14721490
- \showdate "%m.%d%y" 14-3-2015
1491+
- \showdate "%lA %0d-%0m-%Y %H:%M:%S" 14-3-2015 03:04:15
1492+
- \showdate "%lA %0d-%0m-%Y %H:%M:%S" 14-3-2015 03:04
14731493
\endcode
14741494
In case `OUTPUT_LANGUAGE=english` this results in:
14751495
- Saturday 14-03-2015
14761496
- Sat 14-3-15
14771497
- 3.1415
1498+
- Saturday 14-03-15 3:4:15
1499+
- Saturday 14-03-15 3:4:0
14781500
.
14791501
In case `OUTPUT_LANGUAGE=dutch` this results in:
14801502
- Zaterdag 14-03-15
14811503
- za 14-3-2015
14821504
- 3.1415
1505+
- Zaterdag 14-03-15 3:4:15
1506+
- Zaterdag 14-03-15 3:4:0
14831507
.
14841508
<hr>
14851509
\section cmddeprecated \\deprecated { description }

src/docnode.cpp

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,8 @@ void DocPara::handleShowDate(DocNodeVariant *thisVariant)
32253225
parser()->tokenizer.setStateShowDate();
32263226
tok = parser()->tokenizer.lex();
32273227
std::tm dat = tm{};
3228-
if (tok == 0)
3228+
QCString specDate = parser()->context.token->name.stripWhiteSpace();
3229+
if (specDate.isEmpty())
32293230
{
32303231
dat = getCurrentDateTime();
32313232
}
@@ -3237,19 +3238,66 @@ void DocPara::handleShowDate(DocNodeVariant *thisVariant)
32373238
}
32383239
else
32393240
{
3240-
int day, month, year;
3241-
sscanf(parser()->context.token->name.stripWhiteSpace().data(),"%d-%d-%d", &day, &month, &year);
3242-
dat.tm_year = year-1900;
3243-
dat.tm_mon = month-1;
3244-
dat.tm_mday = day;
3241+
int day=0, month=0, year=0;
3242+
int hr=0, min=0, sec=0;
3243+
dat = getCurrentDateTime(); // Filling with default values
3244+
if (sscanf(specDate.data(),"%d-%d-%d %d:%d:%d", &day, &month, &year, &hr, &min, &sec) == 6)
3245+
{
3246+
dat.tm_year = year-1900;
3247+
dat.tm_mon = month-1;
3248+
dat.tm_mday = day;
3249+
dat.tm_hour = hr;
3250+
dat.tm_min = min;
3251+
dat.tm_sec = sec;
3252+
}
3253+
else if (sscanf(specDate.data(),"%d-%d-%d %d:%d", &day, &month, &year, &hr, &min) == 5)
3254+
{
3255+
dat.tm_year = year-1900;
3256+
dat.tm_mon = month-1;
3257+
dat.tm_mday = day;
3258+
dat.tm_hour = hr;
3259+
dat.tm_min = min;
3260+
dat.tm_sec = 0;
3261+
}
3262+
else if (sscanf(specDate.data(),"%d-%d-%d", &day, &month, &year) == 3)
3263+
{
3264+
dat.tm_year = year-1900;
3265+
dat.tm_mon = month-1;
3266+
dat.tm_mday = day;
3267+
dat.tm_hour = 0;
3268+
dat.tm_min = 0;
3269+
dat.tm_sec = 0;
3270+
}
3271+
else if (sscanf(specDate.data(),"%d:%d:%d", &hr, &min, &sec) == 3)
3272+
{
3273+
dat.tm_hour = hr;
3274+
dat.tm_min = min;
3275+
dat.tm_sec = sec;
3276+
}
3277+
else if (sscanf(specDate.data(),"%d:%d", &hr, &min) == 2)
3278+
{
3279+
dat.tm_hour = hr;
3280+
dat.tm_min = min;
3281+
dat.tm_sec = 0;
3282+
}
3283+
else
3284+
{
3285+
warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"invalid or non representable date argument for command '\\showdate'");
3286+
parser()->tokenizer.setStatePara();
3287+
return;
3288+
}
32453289
int weekday;
3290+
// there are some problems when the hr:min:sec are on 00:00:00 in determining the weekday
3291+
hr = dat.tm_hour;
3292+
dat.tm_hour = 12;
32463293
if (!valid_tm(dat,&weekday))
32473294
{
32483295
warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"invalid or non representable date argument for command '\\showdate'");
32493296
parser()->tokenizer.setStatePara();
32503297
return;
32513298
}
32523299
dat.tm_wday = weekday;
3300+
dat.tm_hour = hr;
32533301

32543302
}
32553303

@@ -3287,6 +3335,38 @@ void DocPara::handleShowDate(DocNodeVariant *thisVariant)
32873335
growBuf.addStr(tmp);
32883336
}
32893337
break;
3338+
/* (24-)hour */
3339+
case 'H':
3340+
{
3341+
char tmp[10];
3342+
sprintf(tmp,"%02d",dat.tm_hour);
3343+
growBuf.addStr(tmp);
3344+
}
3345+
break;
3346+
/* (12-)hour */
3347+
case 'I':
3348+
{
3349+
char tmp[10];
3350+
sprintf(tmp,"%02d",dat.tm_hour%12);
3351+
growBuf.addStr(tmp);
3352+
}
3353+
break;
3354+
/* minute */
3355+
case 'M':
3356+
{
3357+
char tmp[10];
3358+
sprintf(tmp,"%02d",dat.tm_min);
3359+
growBuf.addStr(tmp);
3360+
}
3361+
break;
3362+
/* second */
3363+
case 'S':
3364+
{
3365+
char tmp[10];
3366+
sprintf(tmp,"%02d",dat.tm_sec);
3367+
growBuf.addStr(tmp);
3368+
}
3369+
break;
32903370
default:
32913371
/* we just handle the % and 0 here */
32923372
p--;
@@ -3356,6 +3436,22 @@ void DocPara::handleShowDate(DocNodeVariant *thisVariant)
33563436
case 'A':
33573437
growBuf.addStr(theTranslator->trDayOfWeek(getDayOfWeek(dat),false,true));
33583438
break;
3439+
/* (24-)hour */
3440+
case 'H':
3441+
growBuf.addStr(QCString().setNum(dat.tm_hour));
3442+
break;
3443+
/* (12-)hour */
3444+
case 'I':
3445+
growBuf.addStr(QCString().setNum(dat.tm_hour%12));
3446+
break;
3447+
/* minute */
3448+
case 'M':
3449+
growBuf.addStr(QCString().setNum(dat.tm_min));
3450+
break;
3451+
/* second */
3452+
case 'S':
3453+
growBuf.addStr(QCString().setNum(dat.tm_sec));
3454+
break;
33593455
default:
33603456
growBuf.addChar('%');
33613457
growBuf.addChar(c);

src/doctokenizer.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ REFWORD_NOCV {FILEMASK}|{LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV}
342342
RCSID "$"("Author"|"Date"|"Header"|"Id"|"Locker"|"Log"|"Name"|"RCSfile"|"Revision"|"Source"|"State")":"[^:\n$][^\n$]*"$"
343343
LINENR {BLANK}*[1-9][0-9]*
344344

345-
SHOWDATE [0-9][0-9]?"-"[0-9][0-9]?"-"[0-9][0-9][0-9][0-9]
345+
SHOWDATE ([0-9][0-9]?"-"[0-9][0-9]?"-"[0-9][0-9][0-9][0-9])?({WS}*[0-9][0-9]?":"[0-9][0-9]?(":"[0-9][0-9]?)?)?
346346

347347
%option noyywrap
348348

0 commit comments

Comments
 (0)