PHP JSON API dateint, Need some help.

67 views
Skip to first unread message

Travis Brown

unread,
Oct 18, 2012, 2:53:56 AM10/18/12
to fatsecret-p...@googlegroups.com
Whenever I try to make a request to the JSON API via PHP for, let's say exercises for yesterday, I get the same ones as I would get for today even after executing the exercises.commit_day method.  I get no errors from the server or my code, but the data is still the same.  Any suggestions?

Here is my UNIX timestamp to days converter

public static function DaysSinceEpoch($iTimeStamp = null) {
// Check for a timestamp
if (empty($iTimeStamp)) {
// Set the timestamp to the current time
$iTimeStamp = time();
}
// Return the converted value
return strtotime('+'.($iTimeStamp / self::SECONDS_IN_DAY).' days', 0);
}

Where self::SECONDS_IN_DAY is 84600 and $iTimeStamp is the strtotime conversion of my date string

Travis Brown

unread,
Oct 18, 2012, 2:40:15 PM10/18/12
to fatsecret-p...@googlegroups.com
So I realized I the number of seconds were wrong and fixed that, now I am getting an error response from the server

protected 'mLastResponse' => 
    object(stdClass)[53]
      public 'sResponse' => string '<html>

    <head>

        <title>Runtime Error</title>

        <style>

         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 

         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}

         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}

         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }

         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }

         pre {font-family:"Lucida Console";font-size: .9em}

         .marker {font-weight: bold; color: black;text-decoration: none;}

         .version {color: gray;}

         .error {margin-bottom: 10px;}

         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }

        </style>

    </head>



    <body bgcolor="white">



            <span><H1>Server Error in '/rest' Application.<hr width=100% size=1 color=silver></H1>



            <h2> <i>Runtime Error</i> </h2></span>



            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">



            <b> Description: </b>An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

            <br><br>



            <b>Details:</b> To enable the details of this specific error message to be viewable on remote machines, please create a &lt;customErrors&gt; tag within a &quot;web.config&quot; configuration file located in the root directory of the current web application. This &lt;customErrors&gt; tag should then have its &quot;mode&quot; attribute set to &quot;Off&quot;.<br><br>



            <table width=100% bgcolor="#ffffcc">

               <tr>

                  <td>

                      <code><pre>



&lt;!-- Web.Config Configuration File --&gt;



&lt;configuration&gt;

    &lt;system.web&gt;

        &lt;customErrors mode=&quot;Off&quot;/&gt;

    &lt;/system.web&gt;

&lt;/configuration&gt;</pre></code>



                  </td>

               </tr>

            </table>



            <br>



            <b>Notes:</b> The current error page you are seeing can be replaced by a custom error page by modifying the &quot;defaultRedirect&quot; attribute of the application's &lt;customErrors&gt; configuration tag to point to a custom error page URL.<br><br>



            <table width=100% bgcolor="#ffffcc">

               <tr>

                  <td>

                      <code><pre>



&lt;!-- Web.Config Configuration File --&gt;



&lt;configuration&gt;

    &lt;system.web&gt;

        &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt;

    &lt;/system.web&gt;

&lt;/configuration&gt;</pre></code>



                  </td>

               </tr>

            </table>



            <br>



    </body>

</html>

' (length=3030)

Travis Brown

unread,
Oct 18, 2012, 2:53:01 PM10/18/12
to fatsecret-p...@googlegroups.com
This issue has been resolved, the following method will generate a proper dateint for FatSecret


public static function DaysSinceEpoch($iTimeStamp) {
// Return the converted value
return round(($iTimeStamp / self::SECONDS_IN_DAY), 0);
}

Usage:

Remember self::SECONDS_IN_DAY = 86400, not 84600

<?php echo FramsieConverter::DaysSinceEpoch(time()) ?>
<?php echo FramsieConverter::DaysSinceEpoch(strtotime('2012-10-18')) ?>


On Thursday, October 18, 2012 2:53:56 AM UTC-4, Travis Brown wrote:
Reply all
Reply to author
Forward
0 new messages