Developer forum

Forum » Development » dw:DateSelector month + 1 on 31 of the month

dw:DateSelector month + 1 on 31 of the month

Remi Muller
Reply

dw version = 8.2.3.17

 

I have a strange date bug with the dw:DateSelector.

On any custom module when using a dw:DateSelector. Set the current datetime of the server to 31st of the month.

On the dw date selector set a choose a month which does not end on the 31st.

For example february 15.

When saving, the month is saved as march 15. This only happens when the server date is on the 31st of the month.

It only fails if i use the dropdown for setting the month. If i select februari 15 via the graphical date selector then it does save to february 15.

 

I asume the news module or other dw modules use the same control. But on these modules the date is saved correctly.

 

 Does some dev have any idea why this can happen?

 

 

It is not releated to culture settings because only the month is increased and the day is correct. I could imagine that the date month and day were reversed but this is not the case.

 

 

 

 

 

 

 

 

 

 


Replies

 
Remi Muller
Reply
 

Found the problem in the javascript calendar-setup.js -> Calendar.onUpdateDW

 

 See the following proof of concept which demonstrates the shifting month.

 http://jsfiddle.net/U48q5/1/

 

What i don't understand is why the dw modules like newsv2 do not encounter this problem. As far as i can see now they use the same javascript.

 

 

 

 

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Your Fiddle shows behavior I'd expect: it moves to March 3, instead of March 31. The issue in DW seems to be different, no?

 

Imar

 

 
Remi Muller
Reply

This from the dw javascript function "Calendar.onUpdateDW"

var date = new Date();
if (fYear) date.setFullYear(fYear.value);
if (fMonth) date.setMonth(fMonth.value - 1);
if (fDay) date.setDate(fDay.value);
if (fHour) date.setHours(fHour.value);
if (fMinute) date.setMinutes(fMinute.value);

 

As you can see the setMonth can go completely wrong the current new Date() is on the 31st.

 

 

@Imar

It explains the behavior for my custom module perfectly.

I started with februari 15 as input.

new Date() becomes January 31st in my sample.

SetFullYear is done
SetMonth becomes march 3

SetDate sets it to march 15

 

 
Nicolai Høeg Pedersen
Reply

When you insert a date control, it actually renders a Dynamicweb.Dates.DateSelect() control. You can pick up the data using Dynamicweb.Dates.ParseAsDate("YourControlIdOrName")

http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.Dates_members.html

BR Nicolai

 
Remi Muller
Reply

I do not understand where you want to go with this?  (I do not understand you or you do not understand me :)

 

The problem is on the clientside javascript. This where an incorrect date is parsed and then posted.

 
Nicolai Høeg Pedersen
Reply

Hi Remi

Maybe I do not understand...

But the only thing we do all over our system is like this:

In the .aspx:

<dw:DateSelector runat="server" EnableViewState="false" ID="NewsValidUntil" SetNeverExpire="true" />

In the code behind setting the value:

NewsValidUntil.Date = NewsValidUntilView

Saving the value:

NewsValidUntilView = Dates.ParseAsDate("NewsValidUntil")

 

Thats it, no tricks... And it works all over. So I would have to see your entire source code to figure out what goes wrong...

BR Nicolai

 

You must be logged in to post in the forum