[TIMOB-763] TiFilesystemFileProxy.modificationTimestamp() does not return the real value
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:54:10.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | iOS |
Labels | createtimestamp, filesystem, ios, modificationtimestamp |
Reporter | FooMan |
Assignee | Reggie Seagraves |
Created | 2011-04-15T02:35:51.000+0000 |
Updated | 2011-04-17T01:54:10.000+0000 |
Description
Hi,
The TiFilesystemFileProxy.createTimestamp() and TiFilesystemFileProxy.modificationTimestamp() methods return a boolean value rather than the real value. A fix for this is below.
-(id)createTimestamp:(id)args {
NSError * error = nil;
NSDictionary * resultDict = [fm attributesOfItemAtPath:path error:&error];
if (error!=nil) return NUMBOOL(NO);
NSDate * date = [resultDict objectForKey:NSFileCreationDate];
return NUMLONG([date timeIntervalSince1970]);
}
-(id)modificationTimestamp:(id)args {
NSError * error = nil;
NSDictionary * resultDict = [fm attributesOfItemAtPath:path error:&error];
if (error!=nil) return NUMBOOL(NO);
NSDate * date = [resultDict objectForKey:NSFileModificationDate];
return NUMLONG([date timeIntervalSince1970]);
}
The return value of modificationTimestamp() can be used to create a Javascript date like this:
var modificationDate = new Date(Number(timeStamp * 1000));
I have used this to add an HTTP If-Modified-Since header to my image download HTTP requests, like this:
function leadingZero(theNumber) {
return theNumber < 10 ? '0' + theNumber : theNumber;
}
function timeStampToIfModifiedSinceDate(timeStamp) {
var modificationDate = new Date(Number(timeStamp * 1000));
return dayNames[modificationDate.getUTCDay()] + ", " +
leadingZero(modificationDate.getUTCDate()) + " " +
monthNames[modificationDate.getUTCMonth()] + " " +
modificationDate.getUTCFullYear() + " " +
leadingZero(modificationDate.getUTCHours()) + ":" +
leadingZero(modificationDate.getUTCMinutes()) + ":" +
leadingZero(modificationDate.getUTCSeconds()) + " UTC ";
}
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,localFileName);
if (file.exists()) {
httpClient.setRequestHeader("If-Modified-Since",timeStampToIfModifiedSinceDate(Number(file.modificationTimestamp())));
}
NB. On the iPhone simulator, createTimestamp() always returns 0. I haven't tried it on a real device.
Fixed at some point, but definitely resolved as of 1.6.0 RC1.