git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Move common date code to the library file

From
Jonas Fonseca <fonseca@diku.dk>
Date
Apr 26, 2005, 23:55 UTC
Message-ID
<20050426235532.GF28560@diku.dk>
In-Reply-To
<20050426233439.GS13224@pasky.ji.cz>
Move common date conversion code to showdate() library function.
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

--- commit e7ab52f0d69a45e69d78f2992c7997283855ac48 tree 01c206a9520ffa599c3ce17c901b4fce9b162b08 parent 09da825be78580e991bfd0ccbb90de15bfa18113 author Jonas Fonseca <fonseca@diku.dk> Wed, 27 Apr 2005 01:53:04 +0200 committer Jonas Fonseca <fonseca@diku.dk> Wed, 27 Apr 2005 01:53:04 +0200

 cg-Xlib    |    9 +++++++++
 cg-log     |    7 ++-----
 cg-mkpatch |    7 ++-----
 3 files changed, 13 insertions(+), 10 deletions(-)
Index: cg-Xlib
===================================================================
--- 6b45f2ad7c95fa110c7e8b53dae6d099d726bd4c/cg-Xlib  (mode:100755 sha1:5d84bbdb19510b7399f39ffd920636821a37248c)
+++ 01c206a9520ffa599c3ce17c901b4fce9b162b08/cg-Xlib  (mode:100755 sha1:665b84360050e7151eb2aa34327a10821ddc9ccf)
@@ -33,6 +33,15 @@
 	$(which mktemp) $dirarg $prefix"$1"
 }
 
+showdate () {
+	date="$1"
+	sec=${date[0]}; tz=${date[1]}
+	dtz=${tz/+/}
+	lsec=$(expr $dtz / 100 \* 3600 + $dtz % 100 \* 60 + $sec)
+	pdate="$(date -Rud "1970-01-01 UTC + $lsec sec" 2>/dev/null)"
+
+	echo "${pdate/+0000/$tz}"
+}
 
 # Compatibility hacks:
 # 2005-04-26
Index: cg-log
===================================================================
--- 6b45f2ad7c95fa110c7e8b53dae6d099d726bd4c/cg-log  (mode:100755 sha1:1c53b31a956e7c8cbfe653143cc0f91df02a2f86)
+++ 01c206a9520ffa599c3ce17c901b4fce9b162b08/cg-log  (mode:100755 sha1:5d0b602d32068af0d6e958f1c9c4dd6c870a9ce1)
@@ -96,12 +96,9 @@
 				fi
 
 				date=(${rest#*> })
-				sec=${date[0]}; tz=${date[1]}
-				dtz=${tz/+/}
-				lsec=$(expr $dtz / 100 \* 3600 + $dtz % 100 \* 60 + $sec)
-				pdate="$(date -Rud "1970-01-01 UTC + $lsec sec" 2>/dev/null)"
+				pdate="$(showdate $date)"
 				if [ "$pdate" ]; then
-					echo -n $color$key $rest | sed "s/>.*/> ${pdate/+0000/$tz}/"
+					echo -n $color$key $rest | sed "s/>.*/> $pdate/"
 					echo $coldefault
 				else
 					echo $color$key $rest $coldefault
Index: cg-mkpatch
===================================================================
--- 6b45f2ad7c95fa110c7e8b53dae6d099d726bd4c/cg-mkpatch  (mode:100755 sha1:efee5dc887677d3122d8630b9ee3ef396b7adbd3)
+++ 01c206a9520ffa599c3ce17c901b4fce9b162b08/cg-mkpatch  (mode:100755 sha1:c6aa52b6c773718a64feef47a165885b684b593b)
@@ -16,12 +16,9 @@
 		case "$key" in
 			"author"|"committer")
 				date=(${rest#*> })
-				sec=${date[0]}; tz=${date[1]}
-				dtz=${tz/+/}
-				lsec=$(expr $dtz / 100 \* 3600 + $dtz % 100 \* 60 + $sec)
-				pdate="$(date -Rud "1970-01-01 UTC + $lsec sec" 2>/dev/null)"
+				pdate="$(showdate $date)"
 				if [ "$pdate" ]; then
-					echo $key $rest | sed "s/>.*/> ${pdate/+0000/$tz}/" >> $header
+					echo $key $rest | sed "s/>.*/> $pdate/" >> $header
 				else
 					echo $key $rest >> $header
 				fi
-- 
Jonas Fonseca
Previous: Petr Baudis
Message 3 of 3 in “cg-mkpatch: Show human-readable dates”
  1. cg-mkpatch: Show human-readable datesJonas Fonseca, Apr 26, 2005
  2. Petr BaudisApr 26, 2005
  3. Move common date code to the library fileJonas Fonseca, Apr 26, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.