Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN shown instead of Create and Modify Datetime #308

Closed
7 of 17 tasks
ShortBusKing opened this issue Mar 28, 2018 · 4 comments
Closed
7 of 17 tasks

NaN shown instead of Create and Modify Datetime #308

ShortBusKing opened this issue Mar 28, 2018 · 4 comments
Assignees
Milestone

Comments

@ShortBusKing
Copy link
Contributor

In raising this issue, I confirm the following (please check boxes):

  • I have read and understood the Wiki. Especially deploy and configuration articles.
  • I have checked that the bug I am reporting can be replicated, or that the feature I am suggesting isn't already present.
  • I have checked the pull requests tab for existing solutions/implementations to my issue/suggestion.
  • I realise that server-side connectors are provided by various contributors. The implementations are vary due to programming language features/limitations or other factors. Thus a particular connector may not implement, or partially implement, the API features.
  • I realise that any changes in configuration options and/or plugin parameters affect the plugin behavior. I specified all the differences from defaults in details.

I use the following server-side connector (check one):

  • PHP connector by servocoder
  • Java connector by fabriceci
  • Python3 Flask connector by jsooter
  • Python3 Flask connector by stevelittlefish
  • NodeJs connector by jlaustill and forestlake
  • ASP.NET Core connector by sinanbozkus
  • ASHX connector by richeflits
  • Other (specified below)

My familiarity with the project is as follows (check one):

  • I have never used the project.
  • I have used the project briefly.
  • I have used the project extensively, but have not contributed previously.
  • I am an active contributor to the project.

Hello,
I am leveraging the ASP.NET Core connector on a windows 2008 R2 server. I would see a 'NaN' for the modified file dates. The issue come from the connector returning a human readable date in the timestamp, which then gets multiplied by 1000. This creates a undefined value. Below is one potential fix written against the javascript library. I also considered updating the connector so that it returns a UNIX timestamp, but I thought this was best as long as it doesn't mess up everyone.

// Converts UNIX timestamp to formatted datetime string
var formatTimestamp = function(timestamp) {
	// if value doesn't look like timestamp
	if (!timestamp || timestamp <= 0) {
		return '';
	}

        ////// proposed fix for windows ////////////
        if (Date.parse(timestamp)) {
            return timestamp;
        } else {
        ////// END proposed fix for windows ////////////

            // Converts UNIX timestamp to formatted datetime string
           var date = new Date();
           date.setTime(timestamp * 1000); // Creates undefined

            // Timezone support requires "iana-tz-data" package:
            // https://github.com/globalizejs/globalize/blob/master/README.md#3-iana-time-zone-data
            return globalize.formatDate(timestamp, config.formatter.datetime);
        }
};
@ShortBusKing ShortBusKing changed the title Date NaN shown instead of Create and Modify Datetime Mar 28, 2018
@psolom
Copy link
Owner

psolom commented Mar 28, 2018

I don't want to overload JS script trying to handle cases "for all occasions". There is a defined format for expected timestamp, so I would prefer the fix for ASP.NET Core connector. If you are able to create a PR (or provide a code snippet at least) for ASP.NET Core connector I would accept it and include into the package.

@ShortBusKing
Copy link
Contributor Author

I fully understand that and completely agree. I know I presented this as a Windows fix but it might still be valuable. Are there situations where a date will parse but shouldn't be displayed?

I'm working with the ASP.NET connector and there are other changes already. What is the proper date format the UI code is expecting?

@psolom
Copy link
Owner

psolom commented Mar 28, 2018

What is the proper date format the UI code is expecting?

Unix timestamp in seconds

I know I presented this as a Windows fix but it might still be valuable.

Ok, makes sense. I would propose it in a different manner. The code snippet below should handle seconds timestamp as well as milliseconds, and also make attempt to turn string into the Date() object. If fail it will return value without formatting. Check if this code snippet works for you:

    var formatTimestamp = function (datetime) {
        var isString = typeof datetime === "string";
        var isInteger = typeof datetime === "number" && Math.floor(datetime) === datetime;

        // invalid argument
        if (!(isString || isInteger)) return '';

        // value look like seconds, while Date() accepts milliseconds
        if (isInteger && datetime < 10000000000) {
            datetime = datetime * 1000
        }

        var date = new Date(datetime);

        // invalid Date() object, display datetime without formatting
        if (!(date instanceof Date) || isNaN(date)) {
            return datetime;
        }

        // Timezone support requires "iana-tz-data" package:
        // https://github.com/globalizejs/globalize/blob/master/README.md#3-iana-time-zone-data
        return globalize.formatDate(date, config.formatter.datetime);
    };

Looking forward your feedback.

I'm working with the ASP.NET connector and there are other changes already.

Awesome! If you will provide a changelog along with PR it would speed up a review.

@ShortBusKing
Copy link
Contributor Author

This looks pretty bullet proof to me. :) I've updated the connector to return GMT time in Unix format. It seems to work well with your existing code. It even works correctly with the globalize library.

@psolom psolom added this to the 2.7.5 milestone Apr 1, 2018
@psolom psolom self-assigned this Apr 1, 2018
psolom added a commit that referenced this issue Apr 1, 2018
@psolom psolom closed this as completed Apr 1, 2018
ShortBusKing added a commit to ShortBusKing/RichFilemanager that referenced this issue Apr 23, 2018
Added Recursive Searching support
Added GetInfo() function for completeness
Fixes psolom#308 - NaN shown instead of Create and Modify Datetime 
Fixed bug psolom#314, [Object:Object] instead of cannot find file/dir messages, etc
Reduced the overhead of the Summarize() function

** Image height and width information is not returned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants