#5644: Model->save() on Models/edit zeroes the `seconds` in a datetime/timestamp
field.
----------------------------------------------------------+-----------------
Reporter: sonnygauran | Owner:
Type: Bug | Status:
reopened
Priority: Medium | Milestone:
1.2.x.x
Component: Controller | Version: RC3
Severity: Major | Resolution:
Keywords: seconds date time datetime timestamp save | Php_version: n/a
Cake_version: 1.2.0.7692 RC3 |
----------------------------------------------------------+-----------------
Changes (by sonnygauran):
* status: closed => reopened
* resolution: needmoreinfo =>
Comment:
Diff attached. :D
{{{
--- form.php
+++ form (copy).php
@@ -55,7 +55,7 @@
* @var array
*/
var $__options = array(
- 'day' => array(), 'minute' => array(), 'hour' => array(),
+ 'day' => array(),'second' => array(), 'minute' => array(),
'hour' => array(),
'month' => array(), 'year' => array(), 'meridian' =>
array()
);
/**
@@ -1404,6 +1404,47 @@
);
}
/**
+ * Returns a SELECT element for seconds.
+ *
+ * @param string $fieldName Prefix name for the SELECT element
+ * @param string $selected Option which is selected.
+ * @param string $attributes Array of Attributes
+ * @param bool $showEmpty True to show an empty element, or a string to
provide default empty element text
+ * @return string
+ */
+ function second($fieldName, $selected = null, $attributes =
array(), $showEmpty = true) {
+ if ((empty($selected) || $selected === true) && $value =
$this->value($fieldName)) {
+ if (is_array($value)) {
+ extract($value);
+ $selected = $sec;
+ } else {
+ if (empty($value)) {
+ if (!$showEmpty) {
+ $selected = 'now';
+ }
+ } else {
+ $selected = $value;
+ }
+ }
+ }
+
+ if (strlen($selected) > 2) {
+ $selected = date('i', strtotime($selected));
+ } elseif ($selected === false) {
+ $selected = null;
+ }
+ $secondOptions = array();
+
+ if (isset($attributes['interval'])) {
+ $secondOptions['interval'] =
$attributes['interval'];
+ unset($attributes['interval']);
+ }
+ return $this->select(
+ $fieldName . ".sec",
$this->__generateOptions('second', $secondOptions),
+ $selected, $attributes, $showEmpty
+ );
+ }
+/**
* Returns a SELECT element for AM or PM.
*
* @param string $fieldName Prefix name for the SELECT element
@@ -1447,13 +1488,14 @@
* 'monthNames' If set and false numbers will be used for
month select instead of text.
* 'minYear' The lowest year to use in the year select
* 'maxYear' The maximum year to use in the year select
- * 'interval' The interval for the minutes select. Defaults
to 1
+ * 'minInterval' The interval for the minutes select.
Defaults to 1
+ * 'secInterval' The interval for the seconds select.
Defaults to 1
* 'separator' The contents of the string between select
elements. Defaults to '-'
* @param bool $showEmpty Whether or not to show an empty default value.
* @return string The HTML formatted OPTION element
*/
function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat =
'12', $selected = null, $attributes = array(), $showEmpty = true) {
- $year = $month = $day = $hour = $min = $meridian = null;
+ $year = $month = $day = $hour = $min = $sec = $meridian =
null;
if (empty($selected)) {
$selected = $this->value($fieldName);
@@ -1499,24 +1541,22 @@
}
$hour = $time[0];
$min = $time[1];
- }
- }
- }
-
- $elements =
array('Day','Month','Year','Hour','Minute','Meridian');
+ $sec = $time[2];
+ }
+ }
+ }
+
+ $elements =
array('Day','Month','Year','Hour','Minute','Second','Meridian');
$defaults = array(
'minYear' => null, 'maxYear' => null, 'separator'
=> '-',
- 'interval' => 1, 'monthNames' => true
+ 'minInterval' => 1,'secInterval' => 1,
'monthNames' => true
);
$attributes = array_merge($defaults, (array) $attributes);
- if (isset($attributes['minuteInterval'])) {
- $attributes['interval'] =
$attributes['minuteInterval'];
- unset($attributes['minuteInterval']);
- }
+ $secInterval = $attributes['secInterval'];
+ $minInterval = $attributes['minInterval'];
$minYear = $attributes['minYear'];
$maxYear = $attributes['maxYear'];
$separator = $attributes['separator'];
- $interval = $attributes['interval'];
$monthNames = $attributes['monthNames'];
$attributes = array_diff_key($attributes, $defaults);
@@ -1569,14 +1609,18 @@
switch($timeFormat) {
case '24':
- $selectMinuteAttr['interval'] = $interval;
+ $selectMinuteAttr['interval'] =
$minInterval;
+ $selectSecondAttr['interval'] = $secInterval;
$opt .= $this->hour($fieldName, true,
$hour, $selectHourAttr, $showEmpty) . ':' .
- $this->minute($fieldName, $min,
$selectMinuteAttr, $showEmpty);
+ $this->minute($fieldName, $min,
$selectMinuteAttr, $showEmpty) . ':' .
+ $this->second($fieldName, $sec, $selectSecondAttr,
$showEmpty);
break;
case '12':
- $selectMinuteAttr['interval'] = $interval;
+ $selectMinuteAttr['interval'] =
$minInterval;
+ $selectSecondAttr['interval'] = $secInterval;
$opt .= $this->hour($fieldName, false,
$hour, $selectHourAttr, $showEmpty) . ':' .
- $this->minute($fieldName, $min,
$selectMinuteAttr, $showEmpty) . ' ' .
+ $this->minute($fieldName, $min,
$selectMinuteAttr, $showEmpty) . ':' .
+ $this->second($fieldName, $sec, $selectSecondAttr,
$showEmpty) . ' ' .
$this->meridian($fieldName, $meridian,
$selectMeridianAttr, $showEmpty);
break;
case 'NONE':
@@ -1720,16 +1764,28 @@
$data = array();
switch ($name) {
- case 'minute':
+ case 'second':
if (isset($options['interval'])) {
- $interval = $options['interval'];
+ $secinterval =
$options['interval'];
} else {
- $interval = 1;
+ $secinterval = 1;
}
$i = 0;
while ($i < 60) {
$data[$i] = sprintf('%02d', $i);
- $i += $interval;
+ $i += $secinterval;
+ }
+ break;
+ case 'minute':
+ if (isset($options['interval'])) {
+ $mininterval =
$options['interval'];
+ } else {
+ $mininterval = 1;
+ }
+ $i = 0;
+ while ($i < 60) {
+ $data[$i] = sprintf('%02d', $i);
+ $i += $mininterval;
}
break;
case 'hour':
}}}
--
Ticket URL: <https://trac.cakephp.org/ticket/5644#comment:3>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---