diff options
Diffstat (limited to 'main/src/cgeo/geocaching/utils')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/AngleUtils.java | 28 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/DateUtils.java | 18 |
2 files changed, 46 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/AngleUtils.java b/main/src/cgeo/geocaching/utils/AngleUtils.java new file mode 100644 index 0000000..e2b4a66 --- /dev/null +++ b/main/src/cgeo/geocaching/utils/AngleUtils.java @@ -0,0 +1,28 @@ +package cgeo.geocaching.utils; + +public class AngleUtils { + + private AngleUtils() { + // Do not instantiate + } + + /** + * Return the angle to turn of to go from an angle to the other + * + * @param from the origin angle in degrees + * @param to the target angle in degreees + * @return a value in degrees, in the [-180, 180[ range + */ + public static float difference(final float from, final float to) { + return normalize(to - from + 180) - 180; + } + + /** + * Normalize an angle so that it belongs to the [0, 360[ range. + * @param angle the angle in degrees + * @return the same angle in the [0, 360[ range + */ + public static float normalize(final float angle) { + return (angle >= 0 ? angle : (360 - ((-angle) % 360))) % 360; + } +} diff --git a/main/src/cgeo/geocaching/utils/DateUtils.java b/main/src/cgeo/geocaching/utils/DateUtils.java new file mode 100644 index 0000000..3004bdb --- /dev/null +++ b/main/src/cgeo/geocaching/utils/DateUtils.java @@ -0,0 +1,18 @@ +package cgeo.geocaching.utils; + +import java.util.Calendar; + +public class DateUtils { + public static int daysSince(long date) { + final Calendar logDate = Calendar.getInstance(); + logDate.setTimeInMillis(date); + logDate.set(Calendar.SECOND, 0); + logDate.set(Calendar.MINUTE, 0); + logDate.set(Calendar.HOUR, 0); + final Calendar today = Calendar.getInstance(); + today.set(Calendar.SECOND, 0); + today.set(Calendar.MINUTE, 0); + today.set(Calendar.HOUR, 0); + return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d); + } +} |
