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

مشکل unit timestamp در onSelect و مشکل سال در تقویم #427

Open
asefdornica opened this issue Nov 19, 2024 · 0 comments

Comments

@asefdornica
Copy link

asefdornica commented Nov 19, 2024

سلام این کد منه من 2 مشکل دارم من اول month picker دارم که اگر به سال بعد بریم در صفحه ماه سال تغییر نمیکند و همچنین در onSelect متغیر unix مقدار timstamp رو برنمیگردونه که مجبور شدن اونو با persianDate دستی بنویسم.

اینم کد js لطفا کمکم کنید.

    $.mask.definitions["y"] = "[1]";
    $.mask.definitions["#"] = "[34]";
    $.mask.definitions["m"] = "[01]";
    $.mask.definitions["d"] = "[0123]";
    $.mask.definitions["h"] = "[012]";
    $.mask.definitions["i"] = "[012345]";

    $("#start_date").mask("y#99-m9");
    $("#end_date").mask("y#99-m9");

    window.from = $("#start_date").persianDatepicker({
        dayPicker: {
            "enabled": false,
            "titleFormat": "YYYY MMMM"
        },
        viewMode: 'month',
        toolbox: {
            calendarSwitch: {
                enabled: false,
            },
        },
        initialValueType: "persian",
        persianDigit: false,
        initialValue: false,
        observer: true,
        autoClose: true,
        calendarType: "persian",
        format: "YYYY-MM",
        onSelect: function (unix) {
            const dateString = $('#start_date').val();
            const [year, month] = dateString.split("-").map(Number);
            const persianDateData = new persianDate([year, month , 15]);
            const gregorianDate = new Date(persianDateData.toLocale('en-GB'));
            const unixTimestamp = Math.floor(gregorianDate.getTime() );
            unix = unixTimestamp;
            console.log('unix',unix);
            from.touched = true;
            if (from.touched == true) {
                document.getElementById("end_date").value = null;
                window.to = $("#end_date").persianDatepicker({
                    dayPicker: {
                        "enabled": false,
                        "titleFormat": "YYYY MMMM"
                    },
                    viewMode: 'month',
                    toolbox: {
                        calendarSwitch: {
                            enabled: false,
                        },
                    },
                    initialValueType: "persian",
                    persianDigit: false,
                    initialValue: false,
                    observer: true,
                    autoClose: true,
                    calendarType: "persian",
                    format: "YYYY-MM",
                    minDate:unix,
                    onSelect: function (unix) {
                        to.touched = true;
                        if (from && from.options && from.options.maxDate != unix) {
                            var cachedValue = from.getState().selected.unixDate;
                        }
                    },
                });
            }
            if (to && to.options && to.options.minDate != unix) {
                var cachedValue = to.getState().selected.unixDate;
                to.options = {
                    minDate: unix,
                };
            }
        },
    });

    $("#end_date").persianDatepicker({
        dayPicker: {
            "enabled": false,
            "titleFormat": "YYYY MMMM"
        },
        viewMode: 'month',
        toolbox: {
            calendarSwitch: {
                enabled: false,
            },
        },
        initialValueType: "persian",
        initialValue: false,
        observer: true,
        autoClose: true,
        calendarType: "persian",
        format: "YYYY-MM",
    });`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant