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.085 seconds

  I found "cook" two days ago. Played around with it for a day and then within a day got rid of two legacy applications in IBM Lotus Domino Notes and replaced them with "cook". It was really easy. A piece of cake. Actually it was even easier than cooking. Cooking involves more work than developing with "cook". What can I say about "cook"? Great application great price for what it delivers great forum with a lot of information and fast responses active and friendly community fast forward moving development cycle So what should I say "Monsieur Le Cook"? Keep the good work going it will lead to success. Having become a paying member in the words of Edith Piaf may I say ..... non rien de rien ... je ne regrette rien. Vive La France.
FK (JED)
         

Get Started