Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Coding Error in dates.php 19 Sep 2016 15:44 #14556

  • koenvdz
  • koenvdz's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 24
  • Thank you received: 2
Hi Admin,

I was using the timeFromFormat method and getting a wrong result, So I checked the methods in dates.php (so I am using it wrong or there really is an error in the method)
ex:
input : StartDate & StartTime: string(10) "2016-10-27" & string(8) "16:09:00
call to method : $startunix = GuidemanHelperDates::timeFromFormat($data->start_date . ' ' . $data->start_time, '%Y-%m-%d %H:%M:%S');
Result:
In explodeDate() ==> Pos: array(7) { ["minute"]=> bool(false) ["year2"]=> bool(false) ["second"]=> bool(false) ["year4"]=> int(1) ["month"]=> int(4) ["day"]=> int(7) ["hour"]=> int(10) }
array(6) { ["year"]=> string(4) "2016" ["month"]=> string(2) "10" ["day"]=> string(2) "27" ["hour"]=> string(2) "16" ["minute"]=> string(2) "00" ["second"]=> string(2) "00" }

When you change the following code in the explodeDate() method:
//Prepare the search depending on attempted format
$pos = array();
$pos = strpos($format, "Y");
$pos = strpos($format, "y");
$pos = strpos($format, "m");
$pos = strpos($format, "d");

$pos = strpos($format, "H");
$pos = strpos($format, "i");
$pos = strpos($format, "s");
to :
//Prepare the search depending on attempted format
$pos = array();
$pos = strpos($format, "Y");
$pos = strpos($format, "y");
$pos = strpos($format, "m");
$pos = strpos($format, "d");

$pos = strpos($format, "H");
$pos = strpos($format, "M");
$pos = strpos($format, "S");

it works fine.
Result =
Pos: array(7) { ["year2"]=> bool(false) ["year4"]=> int(1) ["month"]=> int(4) ["day"]=> int(7) ["hour"]=> int(10) ["minute"]=> int(13) ["second"]=> int(16) }
array(6) { ["year"]=> string(4) "2016" ["month"]=> string(2) "10" ["day"]=> string(2) "27" ["hour"]=> string(2) "16" ["minute"]=> string(2) "09" ["second"]=> string(2) "00" }

Kind Regards,
Koen
Koen

Please Log in or Create an account to join the conversation.

Coding Error in dates.php 19 Sep 2016 17:52 #14558

M is the format for a short textual representation of a month, three letters, see php.net/manual/en/function.date.php

You should not format with %M, but with %i (correct php format)
The parameter declaration in timeFromFormat and explodeDate is wrong..

So: $startunix = GuidemanHelperDates::timeFromFormat($data->start_date . ' ' . $data->start_time, '%Y-%m-%d %H:%i:%s');
-> lowercase s
The following user(s) said Thank You: koenvdz

Please Log in or Create an account to join the conversation.

Last edit: by Romkabouter.

Coding Error in dates.php 19 Sep 2016 18:32 #14559

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Exact.
The minutes are " i " in php.

Also, you can remove the % because this is old stuff. You don't need them at all.
Look at your component, we are not using that anymore.
and for the seconds, the 's' must be lowercase.
Coding is now a piece of cake
The following user(s) said Thank You: koenvdz

Please Log in or Create an account to join the conversation.

Last edit: by admin.

Coding Error in dates.php 19 Sep 2016 19:02 #14560

  • koenvdz
  • koenvdz's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 24
  • Thank you received: 2
Hi Romkabouter and Admin, you are both right, I got misled by the param description in the comments of the method, I tried with %i and %s and it does not give a result (all zeroes), but if you drop the % like admin suggested it works fine. Thanks.
Koen

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.062 seconds

Real time saver and great Component Builder tool ! I have been developing with J-Cook Pro Component Builder for several months now and can say with all honesty that this product/service is second to none. The product is feature rich and is being improved and added to all the time. Do yourself a favor if you need to build a Joomla! Component then you can do no wrong in trying the product. You will save on time and effort while being able to deliver your project on time. J-Cook pro does the hard work for you you then have the freedom to fully customise the end result for your own needs. 

One word: Awesome.
Edwardcox (JED)
         

Get Started