Skip to content

Commit 88dcf47

Browse files
committed
Datetime storage and display.
- Changed the storage format in order to avoid delimited arguments. - Basic date/time display macros. - Framework for easy definition collections of date/timeuser macros.
1 parent c8d746c commit 88dcf47

File tree

3 files changed

+85
-15
lines changed

3 files changed

+85
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.aux
22
*.log
33
*.gih
4+
*.pdf

git-info.sty

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@
88
\newcommand\githeadmail{GITHEADMAIL}
99
\newcommand\githeadcommit{GITHEADCOMMIT}
1010
\newcommand\githeadbranch{GITHEADBRANCH}
11-
\newcommand\githeadyear{1970}
12-
\newcommand\githeadmonth{1}
13-
\newcommand\githeadday{1}
14-
\newcommand\githeadhour{0}
15-
\newcommand\githeadminute{0}
16-
\newcommand\githeadsecond{0}
17-
\newcommand\githeadtzsign{+}
18-
\newcommand\githeadtzhour{0}
19-
\newcommand\githeadtzminute{0}
11+
\newcommand\GI@head@datetime{{1970}{01}{01}{00}{00}{00}{+}{00}{00}}
2012

2113
% semi-private settings
2214
\newcommand\GI@max@depth{8}
@@ -99,7 +91,7 @@
9991
\GI@set@export\githeadbranch{\githeadbranch}%
10092
\GI@set@export\githeadauthor{\githeadauthor}%
10193
\GI@set@export\githeadmail{\githeadmail}%
102-
\GI@set@export\githeaddatetime{\githeaddatetime}}%
94+
\GI@set@export\GI@head@datetime{\GI@head@datetime}}%
10395
\@tempa}
10496

10597
% finding the path to head
@@ -233,11 +225,11 @@
233225
\GI@extract@year
234226
\GI@extract@month@day
235227
\edef\GI@datetime{%
236-
\GI@year-\GI@two@d{\the\GI@month}-\GI@two@d\GI@day
237-
T\GI@two@d\GI@hour:\GI@two@d\GI@min:\GI@two@d\GI@sec
238-
\GI@tzsign\GI@two@d\GI@tzhour\GI@two@d\GI@tzmin}%
228+
{\GI@year}{\GI@two@d{\the\GI@month}}{\GI@two@d\GI@day}%
229+
{\GI@two@d\GI@hour}{\GI@two@d\GI@min}{\GI@two@d\GI@sec}%
230+
{\GI@tzsign}{\GI@two@d\GI@tzhour}{\GI@two@d\GI@tzmin}}%
239231
\edef\@tempa{\endgroup
240-
\GI@set@export@name{git#1datetime}{\GI@datetime}}
232+
\GI@set@export@name{GI@#1@datetime}{\GI@datetime}}
241233
\@tempa}
242234

243235
\newcommand\GI@parse@timezone[5]{%
@@ -248,6 +240,66 @@
248240
\newcommand\GI@two@d[1]{%
249241
\ifnum#1<10 0\number#1\else \number#1\fi}
250242

243+
% displaying date - internal macros
244+
245+
\newcommand\GI@dt@date [9] {#1-#2-#3}
246+
\newcommand\GI@dt@time [9] {#4:#5:#6}
247+
\newcommand\GI@dt@timezone[9] {#7#8:#9}
248+
\newcommand\GI@dt@datetime[9] {#1-#2-#3T#4:#5:#6#7#8:#9}
249+
250+
\newcommand\GI@dt@year [9] {#1}
251+
\newcommand\GI@dt@month [9] {#2}
252+
\newcommand\GI@dt@day [9] {#3}
253+
\newcommand\GI@dt@hour [9] {#4}
254+
\newcommand\GI@dt@min [9] {#5}
255+
\newcommand\GI@dt@sec [9] {#6}
256+
\newcommand\GI@dt@tzsign[9] {#7}
257+
\newcommand\GI@dt@tzhour[9] {#8}
258+
\newcommand\GI@dt@tzmin [9] {#9}
259+
260+
\newcommand\GI@dt@today[9]{%
261+
\@ifundefined{today}{%
262+
\PackageError{git-info}{%
263+
\noexpand\today undefined! Did you load babel?}{%
264+
You cannot use \noexpand\gitXXXtoday macros if
265+
\noexpand\today is undefined.\MessageBreak
266+
This macro is usually defined by the babel package.}%
267+
}{%
268+
\begingroup
269+
\year#1 \month#2 \day#3
270+
\today
271+
\endgroup}}
272+
273+
% displaying date - defining user macros
274+
275+
\newcommand\GI@def@dt@macro[2]{%
276+
\begingroup
277+
\edef\@tempa{\endgroup
278+
\noexpand\newcommand
279+
\expandafter\noexpand\csname git#1#2\endcsname{%
280+
\noexpand\expandafter
281+
\expandafter\noexpand\csname GI@dt@#2\endcsname
282+
\expandafter\noexpand\csname GI@#1@datetime\endcsname}}%
283+
\@tempa}
284+
285+
\newcommand\GI@def@dt@collection[1]{%
286+
\GI@def@dt@macro{#1}{today}%
287+
\GI@def@dt@macro{#1}{datetime}%
288+
\GI@def@dt@macro{#1}{date}%
289+
\GI@def@dt@macro{#1}{time}%
290+
\GI@def@dt@macro{#1}{timezone}%
291+
\GI@def@dt@macro{#1}{year}%
292+
\GI@def@dt@macro{#1}{month}%
293+
\GI@def@dt@macro{#1}{day}%
294+
\GI@def@dt@macro{#1}{hour}%
295+
\GI@def@dt@macro{#1}{min}%
296+
\GI@def@dt@macro{#1}{sec}%
297+
\GI@def@dt@macro{#1}{tzsign}%
298+
\GI@def@dt@macro{#1}{tzhour}%
299+
\GI@def@dt@macro{#1}{tzmin}}
300+
301+
\GI@def@dt@collection{head}
302+
251303
% main
252304

253305
\GI@check@repo@prefix

test-git-info.tex

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
\documentclass{minimal}
22
\usepackage[utf8]{inputenc}
33
\usepackage[T1]{fontenc}
4+
\usepackage[english]{babel}
45
\usepackage{ted, trace}
56
\usepackage{git-info}
67

@@ -31,11 +32,27 @@
3132
\message{^^J#2: -=|#1|=-^^J}}
3233

3334
\showval\githeadcommit{Git commit}
34-
\showval\githeaddatetime{Git datetime}
3535
\showval\githeadbranch{Git branch}
3636
\showval\githeadauthor{Git author}
3737
\showval\githeadmail{Git mail}
38+
\showval\githeaddatetime{Git head datetime}
39+
40+
% \showval\githeaddate{Git head date}
41+
% \showval\githeadtime{Git head time}
42+
% \showval\githeadtimezone{Git head timezone}
43+
% \showval\githeadyear{Git head year}
44+
% \showval\githeadmonth{Git head month}
45+
% \showval\githeadday{Git head day}
46+
% \showval\githeadhour{Git head hour}
47+
% \showval\githeadmin{Git head min}
48+
% \showval\githeadsec{Git head sec}
49+
% \showval\githeadtzsign{Git head tzsing}
50+
% \showval\githeadtzhour{Git head tzhour}
51+
% \showval\githeadtzmin{Git head tzmin}
3852

3953
\begin{document}
4054

55+
% Not expandable, so must be tested in typesetting context only.
56+
Githeadtoday: -=|\githeadtoday|=-\par
57+
4158
\end{document}

0 commit comments

Comments
 (0)