View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
10011Bug reportsSurvey editingpublic2016-01-22 08:54
Reporterakeyser Assigned ToDenisChenu  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version2.06+ 
Fixed in Version2.06+ 
Summary10011: Date/Time "Dropdown Boxes" functionality does not respect min/max date values set to a calculated date (such as "now")
Description

Date/Time "Dropdown Boxes" functionality does not respect min/max date values that are set to "now", but the alternative to "Dropdown Boxes" (the Date Picker) does.

Steps To Reproduce

Attached is a lss file that exposes the issue at hand.

The first question clearly exposes this bug: With a Date/Time field set to use Dropdown Boxes, with a Maximum date set to "now", the Year component of the picker is not restricted to the current year.

The second question uses the same Maximum Date ("now"), but instead uses the Date/Time picker. This configuration correctly limits the year picker to the current year, but for our purposes we do not wish to use the date/time picker (it has some bugs of its own).

The third question uses the same configuration as the first, except the "now" Maximum Date is replaced with 2017. With this configuration, the drop down box for Year does respect the indicated maximum date.

All of the above scenarios actually display the proper minimum/maximum constraints above the date pickers.

Additional Information

This also fails with other non-date strings that would normally be calculated by php "strtotime", like "-2 years", or "+7 weeks".

To me, it seems like the code that generates the dropdown boxes for the Date/Time picker is not first running "strtotime" against the provided string, unlike the rest of the areas in which it is used, and thus it fails to generate correct dropdowns as a result.

TagsNo tags attached.
Attached Files
Bug heat8
Complete LimeSurvey version number (& build)151018
I will donate to the project if issue is resolvedNo
BrowserChrome 45+ (Mac)
Database type & versionMySQL 5.6
Server OS (if known)Windows
Webserver software & version (if known)IIS 7
PHP Version5.6.14

Relationships

related to 09643 closedDenisChenu Date/Time question with drop down values fails validation when only one value is selected and MySQL is not the database 

Users monitoring this issue

There are no users monitoring this issue.

Activities

mfavetti

mfavetti

2015-12-10 02:08

developer   ~33835

I don't think this is a bug.

You are using the maximum date field in an unsupported way, so you are getting inconsistent results. The maximum date is sanitized for the dropdown presentation in such a way that it's defaulting the maximum date to the hardcoded maximum value of 2037-12-31.

On the datepicker side, JQuery-ui-datepicker is being passed the string "now", which it also considers an invalid value. However, the default in the datepicker library is to use a new Date object (which defaults to the current time). So it only appears to be working properly there because you got lucky in that the library's defaults coincided with the behavior you desired.

If anything this should be a new feature request to also allow "now" as the maximum value and handle this special case properly. Extending it further, it could parse the maximum value from strtotime as you suggest. However, this is not the current behavior at all.

DenisChenu

DenisChenu

2015-12-10 09:33

developer   ~33839

Hi,

I think it's a bug (send a new lss file next).

Example :

  • Set max to "2015"
  • Set dropdown
  • Set yyyy for format
    => Show 2015 to 1900 (not sure for min)
  • Set max to date("Y",strtotime("now")) => dropdown show 2037.

I think actually : testing if max is a number, but must evaluate if date_max is a number after Expression.

Denis

c_schmitz

c_schmitz

2015-12-10 16:38

administrator   ~33867

Last edited: 2015-12-10 16:38

'now' is not a valid value by any means.
See
https://manual.limesurvey.org/Question_type_-_Date#Minimum_date_.28date_min.29_.28New_in_2.05_.29

akeyser

akeyser

2015-12-10 16:40

reporter   ~33868

Last edited: 2015-12-10 16:44

After submitting this bug I actually discovered exactly what @zerwalter has stated. So yes, I would agree that this is in fact a feature request, as any "hack" that uses "date" or "strtotime" probably wouldn't be executed in a way that works for both types of dropdown implementations.

Prior to reporting, was just playing around with the application and discovered that the functionality "just worked" if "now" was entered while using the JQUI DatePicker. I see now that the actual bug is more like "the JQUI datepicker min/max date is not set to hardcoded minimum and maximum defaults if an invalid date is specified"

DenisChenu

DenisChenu

2015-12-10 16:42

developer   ~33869

@Cartsen : i send a lss file when i have time :).

strtotime("now") is valid http://php.net/manual/fr/function.strtotime.php

Tested too with
strtotime("-18 year")

{date("Y",strtotime("now"))} give 2015 in question text. It work in javascripot, just don't set in dropdown.

We must validate if it's a valid date after EM and not before EM.

c_schmitz

c_schmitz

2015-12-10 16:55

administrator   ~33870

Anyway, we can't just process the expression in PHP because this would make it static and we would lose function.
IMHO EM would need to dynamically remove/add options from the dropdown field depending on the parsed expression and store them somewhere.

DenisChenu

DenisChenu

2015-12-10 17:05

developer   ~33872

Last edited: 2015-12-10 17:06

No : EM don't return Statix if we don't force it :

https://github.com/LimeSurvey/LimeSurvey/blob/master/application/helpers/expressions/em_manager_helper.php#L4334

The questionNum use the step : and return Static only if we don't have variable in same step.

For example :
{date("Y",strtotime("now"))} : 2015
{date("Y",strtotime(if(is_empty(QCOD.NAOK),"now","-10 years"))} give <span id="em_xxx">2015</span>

c_schmitz

c_schmitz

2015-12-10 19:10

administrator   ~33874

Last edited: 2015-12-10 19:15

Right, but if we consider this a buggy behaviour we should fix it completely - and the complete fix would be that it also can be handled dynamically.
If my first question (q1) would be a date question and the second question (q2) would be a date question which has set max_date = q1 it would still not work with your proposed solution and dropdowns - it does work if both questions use the popup calendar, so we should also fix it up so that it works with dropdowns.

DenisChenu

DenisChenu

2015-12-10 19:30

developer   ~33876

Fix it if EM return a fixed string : easy
Fix it if EM return a dynamic string : hard..... (3.0 or 2.6 better)

c_schmitz

c_schmitz

2015-12-10 19:34

administrator   ~33877

ok, can you do the easy part?

DenisChenu

DenisChenu

2015-12-11 12:39

developer   ~33888

Last edited: 2015-12-11 12:40

I go PHP part first.

Think dropdown system can be really broken here.

Example :

  • MAXYEAR What year do you want for max : 2010,2020,2030,2040,2050
  • Date with ranged year from MAXYEAR-5 to MAXYEAR

At start (if MAXYEAR is in same group) : show 2037 for max year.

  • Select 2050
  • Can not choose 2045/2050 year ...

It's a silly situation but ;)

DenisChenu

DenisChenu

2015-12-11 19:33

developer   ~33897

There are nother issue.

Min : date("Y",strtotime("-1 year")) : result :2014
Max : date("Y",strtotime("now")) : result :2015

But : show "answer MUST BE 11/12/2015 (and select ctual day don't work).
Think fix the first issue, fix the second issue.

DenisChenu

DenisChenu

2015-12-13 17:15

developer   ~33904

Thinking:
Y is only old system compatibility.
Hard to have dynamic system with date("Y",strtotime(AnotherDate))

Can break in JS.
Then : allow Y only for real year (number). Alow date always (Y-m-d) is a valid date

DenisChenu

DenisChenu

2015-12-15 19:33

developer   ~33983

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=16545

DenisChenu

DenisChenu

2015-12-16 11:13

developer   ~34001

Fixed : leave open for manual update

Related Changesets

LimeSurvey: master c3ceac2c

2015-12-15 18:33:18

DenisChenu

Details Diff
Fixed issue 10011: Date/Time "Dropdown Boxes" functionality does not respect min/max date values set to a calculated date
Dev: work only with 'fixed' date : JS update of dropdown need more javascript (and EM event)
Dev: must update manual ....
Affected Issues
10011
mod - application/helpers/qanda_helper.php Diff File

LimeSurvey: master 9a09b699

2015-12-15 19:20:53

DenisChenu

Details Diff
Dev: remove some debug ... Affected Issues
10011
mod - application/helpers/qanda_helper.php Diff File

LimeSurvey: master 44c2ff32

2015-12-17 10:58:06

DenisChenu

Details Diff
Dev: 10011 : more detailed help
Dev: don't take EM is it's already a date (format YYYY-MM-DD)
Affected Issues
10011
mod - application/helpers/common_helper.php Diff File
mod - application/helpers/qanda_helper.php Diff File

Issue History

Date Modified Username Field Change
2015-11-02 18:28 akeyser New Issue
2015-11-02 18:28 akeyser File Added: limesurvey_survey_611927.lss
2015-12-10 02:08 mfavetti Note Added: 33835
2015-12-10 09:33 DenisChenu Note Added: 33839
2015-12-10 16:38 c_schmitz Note Added: 33867
2015-12-10 16:38 c_schmitz Note Edited: 33867
2015-12-10 16:40 akeyser Note Added: 33868
2015-12-10 16:42 DenisChenu Note Added: 33869
2015-12-10 16:44 akeyser Note Edited: 33868
2015-12-10 16:55 c_schmitz Note Added: 33870
2015-12-10 17:05 DenisChenu Note Added: 33872
2015-12-10 17:05 DenisChenu Note Edited: 33872
2015-12-10 17:06 DenisChenu Note Edited: 33872
2015-12-10 17:06 DenisChenu Note Edited: 33872
2015-12-10 19:10 c_schmitz Note Added: 33874
2015-12-10 19:11 c_schmitz Note Edited: 33874
2015-12-10 19:11 c_schmitz Note Edited: 33874
2015-12-10 19:15 c_schmitz Note Edited: 33874
2015-12-10 19:30 DenisChenu Note Added: 33876
2015-12-10 19:34 c_schmitz Note Added: 33877
2015-12-11 12:37 DenisChenu Assigned To => DenisChenu
2015-12-11 12:37 DenisChenu Status new => assigned
2015-12-11 12:39 DenisChenu Note Added: 33888
2015-12-11 12:40 DenisChenu Note Edited: 33888
2015-12-11 19:33 DenisChenu Note Added: 33897
2015-12-11 19:34 DenisChenu File Added: limesurvey_survey_dateexemplemore.lss
2015-12-11 19:34 DenisChenu Relationship added related to 09643
2015-12-13 17:15 DenisChenu Note Added: 33904
2015-12-15 19:33 DenisChenu Changeset attached => LimeSurvey master c3ceac2c
2015-12-15 19:33 DenisChenu Note Added: 33983
2015-12-15 19:33 DenisChenu Resolution open => fixed
2015-12-16 08:11 DenisChenu Changeset attached => LimeSurvey master 9a09b699
2015-12-16 11:13 DenisChenu Note Added: 34001
2015-12-17 12:19 DenisChenu Changeset attached => LimeSurvey master 44c2ff32
2015-12-17 12:19 DenisChenu Status assigned => resolved
2015-12-17 12:19 DenisChenu Fixed in Version => 2.06+
2016-01-22 08:54 c_schmitz Status resolved => closed
2019-11-01 17:25 c_schmitz Category Survey design => Survey editing