* Don't autovifivy @fields array entries.
[interchange.git] / code / UserTag / db_date.tag
1 # Copyright 2002-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: db_date.tag,v 1.4 2007-03-30 23:40:56 pajamian Exp $
9
10 # [db-date table format]
11 #
12 # This tag returns the last-modified time of a database table,
13 # 'products' by default. Accepts a POSIX strftime value for
14 # date format; uses '%A %d %b %Y' by default.
15 #
16 UserTag  db-date  Order     table format
17 UserTag  db-date  PosNumber 2
18 UserTag  db-date  Version   $Revision: 1.4 $
19 UserTag  db-date  Routine   <<EOF
20 sub {
21     my ($db, $format) = @_;
22         my ($dbfile, $mtime);
23
24         # use defaults if necessary
25         $db = 'products' unless $db;
26     $format = '%A %d %b %Y' unless $format;
27
28         # build database file name
29         $dbfile = $Vend::Cfg->{ProductDir} . '/' 
30                 . $Vend::Cfg->{Database}{$db}{'file'};
31
32         # get last modified time
33         $mtime = (stat ($dbfile))[9];
34
35         if (defined ($mtime)) {
36                 return POSIX::strftime($format, localtime($mtime));
37         } else {
38                 logError ("Couldn't stat $dbfile: $!\n");
39         }
40 }
41 EOF