Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -124,11 +124,11 @@ struct tm tm; if (gmtime_r(&sec, &tm) == NULL) @throw [OFOutOfRangeException newWithClass: isa]; - strftime(str, 20, "%Y-%m-%d %H:%M:%S", &tm); + strftime(str, 20, "%Y-%m-%dT%H:%M:%S", &tm); #else struct tm *tm; # ifdef OF_THREADS [mutex lock]; @@ -136,11 +136,11 @@ @try { # endif if ((tm = gmtime(&sec)) == NULL) @throw [OFOutOfRangeException newWithClass: isa]; - strftime(str, 20, "%Y-%m-%d %H:%M:%S", tm); + strftime(str, 20, "%Y-%m-%dT%H:%M:%S", tm); # ifdef OF_THREADS } @finally { [mutex unlock]; } # endif Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -13,10 +13,11 @@ #import "OFSeekableStream.h" @class OFString; @class OFArray; +@class OFDate; /** * \brief A class which provides functions to read, write and manipulate files. */ @interface OFFile: OFSeekableStream @@ -89,10 +90,15 @@ * * \param path The new directory to change to */ + (void)changeToDirectory: (OFString*)path; +/** + * \return The date of the last modification of the file + */ ++ (OFDate*)modificationDateOfFile: (OFString*)path; + /** * Changes the mode of a file. * * Only changes read-only flag on Windows. * Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -27,10 +27,11 @@ #import "OFFile.h" #import "OFString.h" #import "OFArray.h" #import "OFThread.h" +#import "OFDate.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "macros.h" #ifdef _WIN32 @@ -390,10 +391,24 @@ @throw [OFChangeFileModeFailedException newWithClass: self path: path mode: mode]; #endif } + ++ (OFDate*)modificationDateOfFile: (OFString*)path +{ + struct stat s; + + if (stat([path cString], &s) == -1) + /* FIXME: Maybe use another exception? */ + @throw [OFOpenFileFailedException newWithClass: self + path: path + mode: @"r"]; + + /* FIXME: We could be more precise on some OSes */ + return [OFDate dateWithTimeIntervalSince1970: s.st_mtime]; +} #ifndef _WIN32 + (void)changeOwnerOfFile: (OFString*)path toOwner: (OFString*)owner group: (OFString*)group Index: tests/OFDateTests.m ================================================================== --- tests/OFDateTests.m +++ tests/OFDateTests.m @@ -31,12 +31,12 @@ TEST(@"+[dateWithTimeIntervalSince1970:microseconds:", (d2 = [OFDate dateWithTimeIntervalSince1970: 3600 * 25 + 5 microseconds: 1])) TEST(@"-[description]", - [[d1 description] isEqual: @"1970-01-01 00:00:00Z"] && - [[d2 description] isEqual: @"1970-01-02 01:00:05.000001Z"]) + [[d1 description] isEqual: @"1970-01-01T00:00:00Z"] && + [[d2 description] isEqual: @"1970-01-02T01:00:05.000001Z"]) TEST(@"-[isEqual:]", [d1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0]] && ![d1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0 microseconds: 1]])