Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-763] TiFilesystemFileProxy.modificationTimestamp() does not return the real value

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:54:10.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelscreatetimestamp, filesystem, ios, modificationtimestamp
ReporterFooMan
AssigneeReggie Seagraves
Created2011-04-15T02:35:51.000+0000
Updated2011-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.

Comments

  1. Stephen Tramer 2011-04-15

    Fixed at some point, but definitely resolved as of 1.6.0 RC1.

JSON Source