Date Problem #84

Closed
opened 2017-05-27 05:28:42 +00:00 by JohnnyMcWeed · 9 comments
JohnnyMcWeed commented 2017-05-27 05:28:42 +00:00 (Migrated from github.com)

I think I found another problem if I'm not missing something... The date doesn't get stored as it should be.
Can be recreated like that:

  • Make a new field (type calendar and data type date) to store the date.
  • Add the field to an admin view
  • Install the component
  • Save a new element / change the date of an element

Component Builder 2.4.6
Joomla 3.7.2
PHP 5.6.26

I think I found another problem if I'm not missing something... The date doesn't get stored as it should be. Can be recreated like that: - Make a new field (type _calendar_ and data type _date_) to store the date. - Add the field to an admin view - Install the component - Save a new element / change the date of an element Component Builder 2.4.6 Joomla 3.7.2 PHP 5.6.26
ro-ot commented 2017-05-28 20:00:27 +00:00 (Migrated from github.com)

Check that you use the correct data type DATETIME the date option does not work well with the Joomla date field, since it has time.

Check that you use the correct data type _DATETIME_ the date option does not work well with the Joomla date field, since it has time.
JohnnyMcWeed commented 2017-05-29 03:28:42 +00:00 (Migrated from github.com)

If I change to data type DATETIME, this happens as well.
The strange thing is that I have two identical fields with that configuration but different field names. One is working, the other is not.

If I change to data type DATETIME, this happens as well. The strange thing is that I have two identical fields with that configuration but different field names. One is working, the other is not.

If you added the second field after your first install of the component, you will need to uninstall the component and reinstall or add the SQL update for the field in the Editing the Joomla Component => Details => Version Updates to insure the the new field is added to the database.

Something like:

ALTER TABLE `#__your_component_view` ADD `showon` VARCHAR( 255 ) NOT NULL AFTER `selectiontype` ;
If you added the second field after your first install of the component, you will need to uninstall the component and reinstall or add the SQL update for the field in the **Editing the Joomla Component => Details => Version Updates** to insure the the new field is added to the database. Something like: ``` ALTER TABLE `#__your_component_view` ADD `showon` VARCHAR( 255 ) NOT NULL AFTER `selectiontype` ; ```
JohnnyMcWeed commented 2017-05-29 06:07:14 +00:00 (Migrated from github.com)

I did uninstall, compile/reinstall, but that doesn't change anything. So for both type datetime and date it doesn't work.

I did uninstall, compile/reinstall, but that doesn't change anything. So for both type datetime and date it doesn't work.

Hmmm that does not happen on my side, so you will need to give us a screen shot of the JCB field view in question or the code in the sql install file of the table that this field belongs to.

Hmmm that does not happen on my side, so you will need to give us a screen shot of the JCB field view in question or the code in the sql install file of the table that this field belongs to.
JohnnyMcWeed commented 2017-05-29 10:30:23 +00:00 (Migrated from github.com)

(Here images with date, but either date or datetime doesn't make any difference). The strange thing is that one field is working, but the other is not...
Endresult after saving:
date3

Field 1:
date

Field 2:
date2

What I forgot to say:
As you can see, it's exactly the same configuration. But anyhow it does display both dates in a different format, once xx-xx-xxxx and once xxxx-xx-xx.

(Here images with date, but either date or datetime doesn't make any difference). The strange thing is that one field is working, but the other is not... **Endresult after saving:** ![date3](https://cloud.githubusercontent.com/assets/9844452/26546437/422e4e9a-446a-11e7-836b-e595e03ee842.png) **Field 1:** ![date](https://cloud.githubusercontent.com/assets/9844452/26546436/422de4f0-446a-11e7-8c23-17e786f687ec.png) **Field 2:** ![date2](https://cloud.githubusercontent.com/assets/9844452/26546438/422e8ae0-446a-11e7-9542-e8cd2124e4c8.png) **What I forgot to say:** As you can see, it's exactly the same configuration. But anyhow it does display both dates in a different format, once _xx-xx-xxxx_ and once _xxxx-xx-xx_.

This seems to work every time.

screenshot from 2017-05-30 08-11-15

You will see that it has a few differences but those worth noticing are

  • Data Type
  • Other Default
  • Null Switch

Joomla Calender type always stores time even if the xml format does not show time

## This seems to work every time. ![screenshot from 2017-05-30 08-11-15](https://cloud.githubusercontent.com/assets/5607939/26570228/a6c3ede2-450f-11e7-9c66-880fa357cfae.png) > You will see that it has a few differences but those worth noticing are + Data Type + Other Default + Null Switch __Joomla Calender type always stores time even if the xml format does not show time__

When using Joomla calendar aways use DATETIME and insure you have the Other default set to 0000-00-00 00:00:00 even if your xml format is %d-%m-%Y

The xml format is only for display, not for storing to database, the Calendar type always stores as %Y-%m-%d %H:%M:%S

When using Joomla calendar aways use **DATETIME** and insure you have the Other default set to **0000-00-00 00:00:00** even if your xml format is _%d-%m-%Y_ The xml format is only for display, not for storing to database, the Calendar type always stores as **%Y-%m-%d %H:%M:%S**

Joomla has date functions that are used to display the date, but I wrote a simple few functions that I use in my static helper class to deal with this:

	/**
	 *	Change to nice fancy date
	 */
	public static function fancyDate($date)
	{
		if (!self::isValidTimeStamp($date))
		{
			$date = strtotime($date);
		}
		return date('jS \o\f F Y',$date);
	}

	/**
	 *	Change to nice fancy day time and date
	 */
	public static function fancyDayTimeDate($time)
	{
		if (!self::isValidTimeStamp($time))
		{
			$time = strtotime($time);
		}
		return date('D ga jS \o\f F Y',$time);
	}

	/**
	 *	Change to nice fancy time and date
	 */
	public static function fancyDateTime($time)
	{
		if (!self::isValidTimeStamp($time))
		{
			$time = strtotime($time);
		}
		return date('(G:i) jS \o\f F Y',$time);
	}

	/**
	 *	Change to nice hour:minutes time
	 */
	public static function fancyTime($time)
	{
		if (!self::isValidTimeStamp($time))
		{
			$time = strtotime($time);
		}
		return date('G:i',$time);
	}

	/**
	 *	Check if string is a valid time stamp
	 */
	public static function isValidTimeStamp($timestamp)
	{
		return ((int) $timestamp === $timestamp)
		&& ($timestamp <= PHP_INT_MAX)
		&& ($timestamp >= ~PHP_INT_MAX);
	}
Joomla has date functions that are used to display the date, but I wrote a simple few functions that I use in my static helper class to deal with this: ``` /** * Change to nice fancy date */ public static function fancyDate($date) { if (!self::isValidTimeStamp($date)) { $date = strtotime($date); } return date('jS \o\f F Y',$date); } /** * Change to nice fancy day time and date */ public static function fancyDayTimeDate($time) { if (!self::isValidTimeStamp($time)) { $time = strtotime($time); } return date('D ga jS \o\f F Y',$time); } /** * Change to nice fancy time and date */ public static function fancyDateTime($time) { if (!self::isValidTimeStamp($time)) { $time = strtotime($time); } return date('(G:i) jS \o\f F Y',$time); } /** * Change to nice hour:minutes time */ public static function fancyTime($time) { if (!self::isValidTimeStamp($time)) { $time = strtotime($time); } return date('G:i',$time); } /** * Check if string is a valid time stamp */ public static function isValidTimeStamp($timestamp) { return ((int) $timestamp === $timestamp) && ($timestamp <= PHP_INT_MAX) && ($timestamp >= ~PHP_INT_MAX); } ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#84
No description provided.