Thanks for the java program Chris, I ran it on the version of the O/S where we 
get the problem and got results that show a last modified date that differs by 
one hour when the time changes due to DST.

Current GMT time (no DST): 2010-10-12 22:53:27 GMT         
 Current local time (with DST): 2010-10-12 15:53:28 PDT     
 File [/Aldon/Aldonls/tomcat20/lib/servlet-api.jar]         
 last modified timestamp: 1231267693000                     
 the file was last modified 55656315 seconds ago            
 last modified as GMT time (no DST): 2009-01-06 18:48:13 GMT
 last modified as local time: 2009-01-06 10:48:13 PST       

Change date to: 03/13/10

java com.aldon.lifetime.permissions.test.TimeChange 
'/Aldon/Aldonls/tomcat20/lib/servlet-api.jar' 
Current GMT time (no DST): 2010-03-13 23:55:24 GMT                              
                  
Current local time (with DST): 2010-03-13 15:55:24 PST                          
                  
File [/Aldon/Aldonls/tomcat20/lib/servlet-api.jar]                              
                  
last modified timestamp: 1231271293000                                          
                  
the file was last modified 37253231 seconds ago                                 
                  
last modified as GMT time (no DST): 2009-01-06 19:48:13 GMT                     
                  
last modified as local time: 2009-01-06 11:48:13 PST 

IBM has said they'll open a discussion with their development team and try to 
get a fix out. 

Thanks to everyone for all the help.

Jane                                              

-----Original Message-----
From: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Sent: Tuesday, October 12, 2010 11:08 AM
To: Tomcat Users List
Subject: Re: Disable class monitoring for reloading container classes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

On 10/10/2010 9:09 AM, André Warnier wrote:
> What would be really nice, is if someone wrote a quick Java equivalent 
> to the perl script I submitted.

See below. There's actually more code than absolutely necessary, but it's more 
straightforward this way.

> Now if you *really* insist, the modified version of the perl program, 
> below, will explicitly use a couple of C functions, themselves using 
> the builtin C structures to get the file's "last modified" time.
> 
> Running C in perl, scary stuff..

Are you submitting an application for an obfuscated C program, here?
Sheesh. What's wrong with a little C code?

Amazing: the C code is shorter than the Java code. *shrug*

Time.java (apologies for any re-formatting done by my emailer)
- ---------

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

public class Time
{
    public static void main(String[] args)
        throws Exception
    {
        if(args.length < 1)
        {
            System.out.println("Usage: java Time <filename>");
            System.exit(1);
        }

        // GMT current time
        Calendar now = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        System.out.println("Current GMT time (no DST): "
                           + format(now));

        // local current time
        now = Calendar.getInstance(); // default = local
        System.out.println("Current local time (with DST): "
                           + format(now));

        // File timestamp
        System.out.println("File [" + args[0] + "]");
        File file = new File(args[0]);

        long timestamp = file.lastModified();

        System.out.println("last modified timestamp: " + timestamp);
        System.out.println("the file was last modified "
                           + ((System.currentTimeMillis() - timestamp) /
1000)
                           + " seconds ago");
        Calendar tstamp = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        tstamp.setTimeInMillis(file.lastModified());

        System.out.println("last modified as GMT time (no DST): "
                           + format(tstamp));

        tstamp = Calendar.getInstance(); // default=local
        tstamp.setTimeInMillis(file.lastModified());

        System.out.println("last modified as local time: "
                           + format(tstamp));
    }

    public static String format(Calendar c)
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
        //        format.setTimeZone(tz);
        format.setTimeZone(c.getTimeZone());

        return format.format(c.getTime());
    }
}

time.c
- ------
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <sys/stat.h>

int main(int argc, char *argv[]) {
  time_t now;
  struct tm *gmt;
  struct tm *local;
  struct stat *fileinfo;
  int retval;
  char *filename;

  if(argc < 2) {
    printf("missing filename\n");
    return 1;
  }
  filename = argv[1];

  gmt   = (struct tm*)malloc(sizeof(struct tm));
  local = (struct tm*)malloc(sizeof(struct tm));

  time(&now);

  gmtime_r(&now, gmt);
  localtime_r(&now, local);

  /* note: asctime adds a newline */
  printf("System raw timestamp: %ld\n", now);
  printf("Current GMT time (no DST): %s", asctime(gmt));
  printf("Current local time (with DST): %s", asctime(local));

  fileinfo = (struct stat *)malloc(sizeof(struct stat));

  printf("File [%s]:\n", filename);

  if(stat(filename, fileinfo)) {
    perror(filename);
  } else {
    gmtime_r(&(fileinfo->st_mtime), gmt);
    localtime_r(&(fileinfo->st_mtime), local);

    printf("last modified timestamp: %ld\n", (long)fileinfo->st_mtime);
    printf("the file was last modified %ld seconds ago\n",
           (now - fileinfo->st_mtime));

    printf("last modified as GMT time (no DST): %s", asctime(gmt));
    printf("last modified as local time (with DST): %s", asctime(local));
  }
  return 0;
}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky0o+QACgkQ9CaO5/Lv0PBbvACeLdBAsYKcpP95KkKvJQCNhBP5
TbUAnAxjQk/yLYhSvoq/uWbcl6b6mbv2
=7yhg
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to