Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
288 views
in CompleteFTP by (350 points)

We have found another change in behaviour when jumping from 12.1.4 to 23.0.4 CompleteFTP Server.

var nFile = new file(event.virtualPath);

var ctime = System.IO.File.GetCreationTimeUtc(nFile.adapterAbsolutePath);

var formattedDT = ctime.GetDateTimeFormats("o");

Old Behaviour:

Previously this would return the file 'creation timestamp' (not modified timestamp available via the JSS API) formatted with the 'o' parameter.

New Behaviour

As of version 23.0.4 of CompleteFTP the function call GetDateTimeFormats("o") is failing as the previous System.IO.File.GetCreationTimeUtc() call appears to be returning the result as a javascript formatted 'string' date instead of a .NET dateTime object that can be further manipulated.

Error returned:
Javascript error: Property 'GetDateTimeFormats' of object is not a function

Are you able to advise what changes we need to make to our JSS scripts in order to maintain compatibility?

1 Answer

0 votes
by (51.6k points)

I'm afraid I don't have the general answer for this issue that you're probably hoping for. The problem, as you guessed, is that .NET DateTime objects are always converted to Javascript Date objects. I just checked and it's a known issue with the new version of the Javascript interpreter we're using. The developer seems to believe that it's a bit of a catch-22 situation and had to make a call one way or the other, so he's not planning to change it. I suppose we could change it ourselves, but that'd no doubt cause a whole range of new issues.

Now, if it's just the GetDateTimeFormats("o") function that you need, then you can use the following Javascript version of that function instead.

function getDateTimeFormatsO(dateObj) {
    function pad(number, length) {
        let str = String(number);
        while (str.length < length) {
            str = '0' + str;
        }
        return str;
    }

    const yyyy = dateObj.getUTCFullYear();
    const MM = pad(dateObj.getUTCMonth() + 1, 2);
    const dd = pad(dateObj.getUTCDate(), 2);
    const HH = pad(dateObj.getUTCHours(), 2);
    const mm = pad(dateObj.getUTCMinutes(), 2);
    const ss = pad(dateObj.getUTCSeconds(), 2);
    const ffffff = pad(dateObj.getUTCMilliseconds(), 3) + '0000'; // JavaScript only supports up to milliseconds

    return `${yyyy}-${MM}-${dd}T${HH}:${mm}:${ss}.${ffffff}Z`;
}

// Usage
const now = new Date();
console.log(getDateTimeFormatsO(now));

Incidentally, I got ChatGPT to write this code for me with the following prompt:

Please write a Javascript function that does the same as the .NET System.DateTime.GetDateTimeFormats method when "o" is passed to it.
by (350 points)
Yep, I've been going through and refactoring all occurrences within the code.
Got it more or less functioning at the moment, just need to complete testing of the change(s).
by (51.6k points)
I'm sorry you had to do that. I had no idea this was a problem until you reported it and I spent a long time trying to find a better solution than the one I presented to you.

Categories

...