Sunday 15 February 2015

php - Calculating Time Granulation -


I need to get the following on a site in PHP.

Our users have a 'granulation value' in their app - that is 14400 which represents 4 hours.

Now, what I basically have to do is track the 'action' based on this granular from midnight - for example, the action is at 03:15, time is 00:00 - The result of 03:59 will be the result, so if any action is at 4:25, then it will be tracked under 04:00 - 07:59.

I am trying to write a function that has the following:

  function _get_granulation ($ grained) {$ time = date ("G: i"); // gives us the current time (like 04:15 or 22:10) $ iterations = ($ granular / 86400); // Number of iterations in a 24 hour period}   

Now I am a little stuck where I go from here.

Specifically, I need it

Can anyone get advice / support here?

You should find this function for whom you are searching:

  Function _get_granulation ($ granulation, $ now = null) {if (is_null ($ now)) $ now = time (); $ DaySecs = Date ('g', now $) * 3600 + date ('I', now $) * 60 + date ('s', $ now); $ Volume = $ grainy * floor ($ daySec / $ granular); $ Hour = floor ($ section / 3600); $ Min = Floor (($ Segment - $ Hours * 3600) / 60); $ Sec = $ Segment - $ hour * 3600 - $ min * 60; Date of Return ('H: I: S', MkTime ($ hour, $ min, $ sec)); }   

I do not use direct UNIX timestamps to avoid problems with Danielle savings, but instead use the actual hour / minute / second value.

I have added an extra parameter to help in testing, so do not always use the current time. This allows a test script:

  $ times = array ('10: 30: 00 ', '07: 59: 00', '23: 20: 00 '); $ Danas = array (21600, 14400, 3600, 1800); Foreign exchange ($ granulations as $ grams) Foreign exchange ($ bar $ T) {$ segment = _get_granulation ($ g, strtotime ($ t)); Echo ("{$ t} / {$ g} = {$ clause} \ n"); }   

Which produces the output like this:

  10:30:00 / 21600 = 06:00:00 07:59:00 / 21600 = 06: 00: 00 23:20:00 / 21600 = 18:00:00 10:30:00 / 14400 = 08:00:00 07:59:00 / 14400 = 04:00:00 23:20 : 00/14400 = 20:00:00 10:30:00 / 3600 = 10:00:00 07:59:00 / 3600 = 07:00:00 23:20:00 / 3600 = 23:00:00 10 : 30: 00/1800 = 10:30:00 07:59:00 / 1800 = 07:30:00 23:20:00 / 1800 = 23:00:00    

No comments:

Post a Comment