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

Calendar parseDate function ignores "utc" parameter #3927

Closed
vadjs opened this issue Sep 13, 2017 · 6 comments
Closed

Calendar parseDate function ignores "utc" parameter #3927

vadjs opened this issue Sep 13, 2017 · 6 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@vadjs
Copy link

vadjs commented Sep 13, 2017

I'm submitting a ... (check one with "x")

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)
http://plnkr.co/edit/lwgFVONK97ACJcCWr1YU?p=preview

Current behavior

Current parseDate function ignores utc="true" parameter.

Expected behavior

New parseDate function should respect utc="true" parameter.

Minimal reproduction of the problem with instructions

http://plnkr.co/edit/lwgFVONK97ACJcCWr1YU?p=preview
Here you see Calendar with utc="true" parameter. Pick date in calendar - you will get date with T00:00:00.000Z. Input same date from keyboard - you will get T21:00:00.000Z.

What is the motivation / use case for changing the behavior?

Properly working of parseDate function.

Please tell us about your environment:

  • Angular version: 4.2.4
  • PrimeNG version: 4.2.0
  • Browser: all
  • Language: all

  • Node (for AoT issues): node --version =

@vadjs
Copy link
Author

vadjs commented Sep 13, 2017

Here are fix: #3928
@cagataycivici i hope you will don't ignore it.

@jonyadamit
Copy link
Contributor

jonyadamit commented Sep 20, 2017

This also applies to the formatDate function imported from jquery-ui.
Setting a date via code, while using [utc] = true will display incorrect date.
I'll paste the fix here if anyone needs it, since I bet this will be ignored as well (this is just the edited JS but should be fairly the same).

Calendar.prototype.formatDate = function (date, format) {
        if (!date) {
            return "";
        }
        var iFormat, lookAhead = function (match) {
            var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
            if (matches) {
                iFormat++;
            }
            return matches;
        }, formatNumber = function (match, value, len) {
            var num = "" + value;
            if (lookAhead(match)) {
                while (num.length < len) {
                    num = "0" + num;
                }
            }
            return num;
        }, formatName = function (match, value, shortNames, longNames) {
            return (lookAhead(match) ? longNames[value] : shortNames[value]);
        }, output = "", literal = false;
        if (date) { 
            for (iFormat = 0; iFormat < format.length; iFormat++) {
                if (literal) {
                    if (format.charAt(iFormat) === "'" && !lookAhead("'"))
                        literal = false;
                    else
                        output += format.charAt(iFormat);
                }
                else {
                    switch (format.charAt(iFormat)) {
                        case "d":
                            output += formatNumber("d", this.utc ? date.getUTCDate() : date.getDate(), 2);
                            break;
                        case "D":
                            output += formatName("D", this.utc ? date.getUTCDay() : date.getDay(), this.locale.dayNamesShort, this.locale.dayNames);
                            break;
                        case "o":
                            if (this.utc)
                                output += formatNumber("o", Math.round((new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()).getUTCTime()) - new Date(Date.UTC(date.getUTCFullYear(), 0, 0).getUTCTime())) / 86400000), 3);
                            else
                                output += formatNumber("o", Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
                            break;
                        case "m":
                            output += formatNumber("m", (this.utc ? date.getUTCMonth() : date.getMonth()) + 1, 2);
                            break;
                        case "M":
                            output += formatName("M", this.utc ? date.getUTCMonth() : date.getMonth(), this.locale.monthNamesShort, this.locale.monthNames);
                            break;
                        case "y":
                            output += (lookAhead("y") ? (this.utc ? date.getUTCFullYear() : date.getFullYear()) :
                                ((this.utc ? date.getUTCFullYear : date.getFullYear()) % 100 < 10 ? "0" : "") + (this.utc ? date.getUTCFullYear() : date.getFullYear()) % 100);
                            break;
                        case "@":
                            output += this.utc ? date.getUTCTime() : date.getTime();
                            break;
                        case "!":
                            output += (this.utc ? date.getUTCTime() : date.getTime()) * 10000 + this.ticksTo1970;
                            break;
                        case "'":
                            if (lookAhead("'"))
                                output += "'";
                            else
                                literal = true;
                            break;
                        default:
                            output += format.charAt(iFormat);
                    }
                }
            }
        }
        return output;
    };

@vadjs
Copy link
Author

vadjs commented Sep 21, 2017

@cagataycivici In past week i presented PrimeNG, and my experience in using it on Angular Moscow meetup. I showed trend of answering on bug reports. After this no one wanted to use PrimeNG.
That's terrible because you are killing PrimeNG with your "non supporting" PrimeNG issues and pull requests on Github.

If nothing changes in next 1-2 months - my current project will be last project using PrimeNG.

@cagataycivici
Copy link
Member

cagataycivici commented Oct 4, 2017

Reviewing this now, our response time for community issues may take up to 1 or 2 months I'm afraid, this is due to the popularity, we've just reached 1 million downloads, please keep submitting PRs and it will definitely be reviewed in a couple of weeks. This is how open source works, I'm doing it for 10+ years, there is PrimeNG PRO to secure our response within 1 business day. Project is way too popular to respond instantly so everything is reviewed with a delay because of the reasons above.

This one particularly has been created 21 days ago which is not bad :) Our capacity for each release (every two-three) weeks is to review 100 community issues and all the PRs submitted during this period.

Also so far close to 3000 community issues are reviewed and closed, so out of 3500, we've done a lot of work on the 3000 issues. If you see it from this point of view, it is easy to understand how much work has been done. Everything is reviewed but not instantly but based on development sprints.

@cagataycivici cagataycivici self-assigned this Oct 4, 2017
@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Oct 4, 2017
@cagataycivici cagataycivici added this to the 4.2.2 milestone Oct 4, 2017
@cagataycivici cagataycivici changed the title [Calendar] parseDate function ignores "utc" parameter Calendar parseDate function ignores "utc" parameter Oct 4, 2017
@cagataycivici
Copy link
Member

@jonyadamit Please create a PR, I could not compile the posted code also not sure if .getUTCTime() exists.

@vadjs
Copy link
Author

vadjs commented Oct 4, 2017

@cagataycivici because this project is very popular, it probably makes much profit to your company. So, you could hire 1-2 more developers for maintain project. Or you can grant commit roles to the several enthusiasts. It's free.
Anyways 1-2 months to review PR is not normal. If bug is critical, it's easier to make new fork. It really stops much developers from using PrimeNG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

3 participants