0 Replies Latest reply on Apr 3, 2012 7:09 AM by lee704

    Date/Time Picker Output Help

    lee704 Level 1

      In my Flex 3.6 app, I have a set of controls that allow the user to pick the date/time.  The user does this by selecting a date from a DateInput, an hour, minutes and AM/PM through three ComboBox.  I then combine the selections into a string and output in a Label control.

       

      I now need to compare the date/time selected to a set of date/times that are allowed.  I keep running into the error "1067: Implicit coercion of a value of type String to an unrelated type Date."

       

      How can I convert my date/time string into a valid date object so I can compare it with other date objects?

       

      Thanks!

      Lee

       

      Below is the code:

       

      DateTimePicker.mxml

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

                                              layout="absolute"

                                              minWidth="955"

                                              minHeight="600">

                <mx:Script>

                          <![CDATA[

                                    [Bindable]

                                    private var todayDate:Date=new Date();

       

       

                                    [Bindable]

                                    private var earliestTime:Date=new Date(todayDate.getTime() + 3 * 60 * 60 * 1000);

       

       

                                    [Bindable]

                                    private var latestTime:Date=new Date(todayDate.getTime() + 12 * 60 * 60 * 1000);

                          ]]>

                </mx:Script>

       

       

                <!--Data-->

                <mx:XML id="hoursXML"

                                    source="assets/hours.xml"/>

       

       

                <mx:XMLListCollection source="{hoursXML.hour}"

                                                                    id="xmllcHours"/>

       

       

                <mx:XML id="minutesXML"

                                    source="assets/minutes.xml"/>

       

       

                <mx:XMLListCollection source="{minutesXML.minute}"

                                                                    id="xmllcMinutes"/>

       

       

                <mx:DateFormatter id="dfd"

                                                          formatString="MM/DD/YYYY"/>

       

       

                <mx:Label x="10"

                                      y="10"

                                      text="Date/Time"/>

       

       

                <mx:DateField x="82"

                                                y="10"

                                                id="dfExpectedDate"

                                                text="{dfd.format(todayDate)}"

                                                selectableRange="{{rangeStart: this.earliestTime,rangeEnd: this.latestTime}}"

                                                visible="true"

                                                width="100"/>

       

       

                <mx:ComboBox x="200"

                                               y="10"

                                               id="cbExpectedHour"

                                               fontWeight="normal"

                                               width="80"

                                               text="Hour"

                                               selectedIndex="-1"

                                               dataProvider="{xmllcHours}">

                </mx:ComboBox>

       

       

                <mx:ComboBox x="300"

                                               y="10"

                                               width="80"

                                               id="cbExpectedMinute"

                                               fontWeight="normal"

                                               selectedIndex="-1"

                                               text="Minute"

                                               dataProvider="{xmllcMinutes}">

                </mx:ComboBox>

       

       

                <mx:ComboBox x="400"

                                               y="10"

                                               width="80"

                                               id="cbExpectedTimeRange"

                                               fontWeight="normal"

                                               selectedIndex="-1"

                                               text="AM/PM">

                          <mx:ArrayCollection>

                                    <mx:Object label="a.m."

                                                           data="AM"/>

                                    <mx:Object label="p.m."

                                                           data="PM"/>

                          </mx:ArrayCollection>

                </mx:ComboBox>

       

       

                <mx:Text x="10"

                                     y="38"

                                     text="{this.dfExpectedDate.text} {this.cbExpectedHour.text}:{this.cbExpectedMinute.text}:00 {this.cbExpectedTimeRange.selectedItem.data}"

                                     id="tExpectedLandingDateTime"

                                     visible="true"/>

      </mx:Application>

       

      hours.xml

      <?xml version="1.0" encoding="utf-8"?>

      <hours>

                <hour>12</hour>

                <hour>01</hour>

                <hour>02</hour>

                <hour>03</hour>

                <hour>04</hour>

                <hour>05</hour>

                <hour>06</hour>

                <hour>07</hour>

                <hour>08</hour>

                <hour>09</hour>

                <hour>10</hour>

                <hour>11</hour>

      </hours>

       

      minutes.mxml

      <?xml version="1.0" encoding="utf-8"?>

      <minutes>

                <minute>00</minute>

                <minute>01</minute>

                <minute>02</minute>

                <minute>03</minute>

                <minute>04</minute>

                <minute>05</minute>

                <minute>06</minute>

                <minute>07</minute>

                <minute>08</minute>

                <minute>09</minute>

                <minute>10</minute>

                <minute>11</minute>

                <minute>12</minute>

                <minute>13</minute>

                <minute>14</minute>

                <minute>15</minute>

                <minute>16</minute>

                <minute>17</minute>

                <minute>18</minute>

                <minute>19</minute>

                <minute>20</minute>

                <minute>21</minute>

                <minute>22</minute>

                <minute>23</minute>

                <minute>24</minute>

                <minute>25</minute>

                <minute>26</minute>

                <minute>27</minute>

                <minute>28</minute>

                <minute>29</minute>

                <minute>30</minute>

                <minute>31</minute>

                <minute>32</minute>

                <minute>33</minute>

                <minute>34</minute>

                <minute>35</minute>

                <minute>36</minute>

                <minute>37</minute>

                <minute>38</minute>

                <minute>39</minute>

                <minute>40</minute>

                <minute>41</minute>

                <minute>42</minute>

                <minute>43</minute>

                <minute>44</minute>

                <minute>45</minute>

                <minute>46</minute>

                <minute>47</minute>

                <minute>48</minute>

                <minute>49</minute>

                <minute>50</minute>

                <minute>51</minute>

                <minute>52</minute>

                <minute>53</minute>

                <minute>54</minute>

                <minute>55</minute>

                <minute>56</minute>

                <minute>57</minute>

                <minute>58</minute>

                <minute>59</minute>

      </minutes>