blob: 26aa64535e7167922b89ab5428ba846db00713b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
% arara: pdflatex
% arara: pdflatex
\documentclass{memoir}
\usepackage[en-GB,showdow]{datetime2}
\usepackage{lipsum}% dummy text
\usepackage[hidelinks]{hyperref}
\newcommand*{\numdash}{\texorpdfstring{\,--\,}{--}}
% \DTMmonthname is robust and can't be used in the bookmarks
% or headings so use \DTMenglishmonthname since this
% document is in English.
\newcommand*{\entrymonth}[2]{\DTMenglishmonthname{#2} #1}
% A range of dates.
% Syntax: \daterange{yyyy1}{mm1}{dd1}{yyyy2}{mm2}{dd2}
\newcommand*{\daterange}[6]{%
\ifnum#1=#4
% Same year
\ifnum#2=#5
% Same month
\ifnum#3=#6
% Same day - not a range!
\DTMdisplaydate{#1}{#2}{#3}%
\else
% Range within the same month.
% This needs to be done explicitly but match the separators
% with the en-GB style.
\DTMenglishordinal{#3}\numdash\DTMenglishordinal{#6}%
\DTMenGBdaymonthsep
\DTMenglishmonthname{#2}%
\DTMenGBmonthyearsep\number#1
\fi
\else
% Not the same month
\DTMdisplaydate{#1}{#2}{#3}{-1}\numdash\DTMdisplaydate{#4}{#5}{#6}{-1}%
\fi
\else
% Not same year
\DTMdisplaydate{#1}{#2}{#3}{-1}\numdash\DTMdisplaydate{#4}{#5}{#6}{-1}%
\fi
}
% range of months
% Syntax: \monthspan{yyyy1}{mm1}{yyyy2}{mm2}
\newcommand*{\monthspan}[4]{%
\ifnum#1=#3
% Same year
\DTMenglishmonthname{#2}\numdash\DTMenglishmonthname{#4}%
\DTMenGBmonthyearsep\number#1
\else
% Not the same year
\DTMenglishmonthname{#2}%
\DTMenGBmonthyearsep\number#1
\numdash\DTMenglishmonthname{#4}%
\DTMenGBmonthyearsep\number#3
\fi
}
\newcommand*{\entrydate}[3]{\DTMdisplaydate{#1}{#2}{#3}{-1}}
\newcommand*{\titleentrydate}[3]{\DTMdate{#1-#2-#3}}
\renewcommand*{\printchaptertitle}[1]{%
{%
\let\entrydate\titleentrydate
\chaptitlefont{#1}%
}%
}
\setsecheadstyle{\let\entrydate\titleentrydate
\Large\bfseries\memRTLraggedright}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Introduction}
This is a test document that illustrates the use of dates within
chapter titles.
\section{Sample}
An example section.
\chapter{\entrymonth{2016}{01}}
\lipsum
\section{\entrydate{2016}{01}{01}}
\lipsum[1-10]
\section{\entrydate{2016}{01}{02}}
\lipsum
\section{\daterange{2016}{01}{04}{2016}{01}{12}}
\lipsum[1-3]
\chapter{\entrydate{2016}{02}{03}}
\lipsum
\chapter{\monthspan{2016}{02}{2016}{03}}
\lipsum
\section{\daterange{2016}{02}{04}{2016}{03}{01}}
\lipsum
\chapter{\monthspan{2015}{12}{2016}{01}}
\lipsum
\section{\daterange{2015}{12}{20}{2016}{01}{01}}
\lipsum
\end{document}
|