Last active
January 5, 2018 10:56
-
-
Save chris-carneiro/a5d08538a3ab433572dc92a34b1b4c22 to your computer and use it in GitHub Desktop.
API used to approximate a time [hh:mm] in seconds that was mistakenly multiplied by 24.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Approximates the minutes given a time in seconds that was mistakenly multiplied by 24.<BR/> | |
* Here is the wrong formula used in the first place. It was used to supposedly calculate a time [hh:mm] in seconds:<BR/> | |
* <pre>hourOfDay * 24 * 3600 + minute * 60</pre> | |
* Here's the formula we've come up with to approximate the minutes:<BR/> | |
* <pre>m ~= (x/60) - (1440*E(x/86400))</pre> | |
* Where x is the time in seconds and E(h) is the hours rounded to floor. | |
* | |
* @param seconds time [hh::mm] in seconds that was multiplied by 24. | |
* @return int | |
*/ | |
public static int getMinutesFromCorrupt(long seconds) { | |
return (((int) seconds / 60) - (int) (1440 * seconds / 86400)); | |
} | |
/** | |
* Approximates the hours part of a time in seconds mistakenly multiplied by 24. | |
* The formula is the following: | |
* <pre>h ~= x/86400</pre> | |
* Where x is the time in seconds. | |
* | |
* @param seconds time [hh::mm] in seconds that was multiplied by 24. | |
* @return int | |
*/ | |
public static int getHourFromCorrupt(long seconds) { | |
return Math.round(seconds / 86400); | |
} | |
/** | |
* Computes a time in milliseconds given a time in seconds mistakenly multiplied by 24. | |
* Formula used: | |
* <pre>x' ~= (E((x/86400)*3600) + ((x/60) - (1440*E(((x/86400)*3600)))) * 60)*1000</pre> | |
* Where E(h) is a floor of h and x in the time in seconds. | |
* | |
* @param seconds time [hh::mm] in seconds that was multiplied by 24. | |
* @return long | |
*/ | |
public static long getMillisFromCorrupt(long seconds) { | |
return ((getHourFromCorrupt(seconds) * 3600) + (getMinutesFromCorrupt(seconds) * 60) * 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment