Adding first code drop
[demorecorder] / src / Constants.vala
diff --git a/src/Constants.vala b/src/Constants.vala
new file mode 100644 (file)
index 0000000..703b27f
--- /dev/null
@@ -0,0 +1,62 @@
+/*  Demo Recorder for MAEMO 5
+*   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
+*   This program is free software; you can redistribute it and/or modify
+*   it under the terms of the GNU General Public License version 2,
+*   or (at your option) any later version, as published by the Free
+*   Software Foundation
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details
+*
+*   You should have received a copy of the GNU General Public
+*   License along with this program; if not, write to the
+*   Free Software Foundation, Inc.,
+*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*/
+namespace IdWorks {
+
+  namespace Time {
+
+    public const string CLOCK_FORMAT = "%02llu:%02llu.%01llu";
+    public static string time_to_string(int64 t) {
+      uint64 ut = (uint64)t / Nanoseconds.MILLISECOND;
+      return CLOCK_FORMAT.printf((ut / Milliseconds.MINUTE), (ut / Milliseconds.SECOND) % Seconds.MINUTE, (ut % Milliseconds.SECOND) / 100);
+    }
+    public static int64 get_current_time() {
+      TimeVal tv = TimeVal();
+      tv.get_current_time();
+      return (((int64)tv.tv_sec * 1000000) + (int64)tv.tv_usec) * 1000;
+    }
+
+    namespace Nanoseconds {
+      public const uint64 NANOSECOND = 1;
+      public const uint64 MILLISECOND = 1000000 * NANOSECOND;
+      public const uint64 SECOND = 1000 * MILLISECOND;
+      public const uint64 MINUTE = 60 * SECOND;
+      public const uint64 HOUR = 60 * MINUTE;
+      public const uint64 DAY = 24 * HOUR;
+      public const uint64 WEEK = 7 * DAY;
+    }
+
+    namespace Milliseconds {
+      public const uint64 MILLISECOND = 1;
+      public const uint64 SECOND = 1000 * MILLISECOND;
+      public const uint64 MINUTE = 60 * SECOND;
+      public const uint64 HOUR = 60 * MINUTE;
+      public const uint64 DAY = 24 * HOUR;
+      public const uint64 WEEK = 7 * DAY;
+    }
+
+    namespace Seconds {
+      public const uint64 SECOND = 1;
+      public const uint64 MINUTE = 60 * SECOND;
+      public const uint64 HOUR = 60 * MINUTE;
+      public const uint64 DAY = 24 * HOUR;
+      public const uint64 WEEK = 7 * DAY;
+    }
+
+  }
+
+}
\ No newline at end of file