1044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/*
2044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Copyright (C) 2011 The Android Open Source Project
3044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
4044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * you may not use this file except in compliance with the License.
6044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * You may obtain a copy of the License at
7044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
8044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
10044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Unless required by applicable law or agreed to in writing, software
11044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * See the License for the specific language governing permissions and
14044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * limitations under the License.
15044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
16044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
17044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/** @file rs_time.rsh
18d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *  \brief Renderscript time routines
19044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams *
20d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *  This file contains Renderscript functions relating to time and date
21d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *  manipulation.
22044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */
23044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams
24ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines#ifndef __RS_TIME_RSH__
25ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines#define __RS_TIME_RSH__
26ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines
27d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/**
28d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Calendar time interpreted as seconds elapsed since the Epoch (00:00:00 on
29d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * January 1, 1970, Coordinated Universal Time (UTC)).
30d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */
31ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinestypedef int rs_time_t;
32ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines
33d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/**
34d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Data structure for broken-down time components.
35d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *
36d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_sec   - Seconds after the minute. This ranges from 0 to 59, but possibly
37d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *            up to 60 for leap seconds.
38d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_min   - Minutes after the hour. This ranges from 0 to 59.
39d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_hour  - Hours past midnight. This ranges from 0 to 23.
40d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_mday  - Day of the month. This ranges from 1 to 31.
41d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_mon   - Months since January. This ranges from 0 to 11.
42d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_year  - Years since 1900.
43d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_wday  - Days since Sunday. This ranges from 0 to 6.
44d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_yday  - Days since January 1. This ranges from 0 to 365.
45d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_isdst - Flag to indicate whether daylight saving time is in effect. The
46d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *            value is positive if it is in effect, zero if it is not, and
47d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *            negative if the information is not available.
48d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */
49ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinestypedef struct {
50d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_sec;     ///< seconds
51d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_min;     ///< minutes
52d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_hour;    ///< hours
53d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_mday;    ///< day of the month
54d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_mon;     ///< month
55d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_year;    ///< year
56d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_wday;    ///< day of the week
57d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_yday;    ///< day of the year
58d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines    int tm_isdst;   ///< daylight savings time
59ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines} rs_tm;
60ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines
61d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/**
62d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Returns the number of seconds since the Epoch (00:00:00 UTC, January 1,
63d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 1970). If @p timer is non-NULL, the result is also stored in the memory
64d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * pointed to by this variable. If an error occurs, a value of -1 is returned.
65d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *
66d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @param timer Location to also store the returned calendar time.
67d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *
68d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Seconds since the Epoch.
69d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */
70ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern rs_time_t __attribute__((overloadable))
71ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines    rsTime(rs_time_t *timer);
72ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines
73d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/**
74d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Converts the time specified by @p timer into broken-down time and stores it
75d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * in @p local. This function also returns a pointer to @p local. If @p local
76d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * is NULL, this function does nothing and returns NULL.
77d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *
78d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @param local Broken-down time.
79d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @param timer Input time as calendar time.
80d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *
81d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Pointer to broken-down time (same as input @p local).
82d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */
83ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern rs_tm * __attribute__((overloadable))
84ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines    rsLocaltime(rs_tm *local, const rs_time_t *timer);
85ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines
86d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/**
87d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Returns the current system clock (uptime) in milliseconds.
88d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *
89d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Uptime in milliseconds.
90d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */
91ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern int64_t __attribute__((overloadable))
92ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines    rsUptimeMillis(void);
93ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines
94d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/**
95d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Returns the current system clock (uptime) in nanoseconds.
96d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *
97d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Uptime in nanoseconds.
98d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */
99ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern int64_t __attribute__((overloadable))
100ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines    rsUptimeNanos(void);
101ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines
102d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/**
103d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Returns the time in seconds since this function was last called in this
104d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * script.
105d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines *
106d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Time in seconds.
107d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */
108ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern float __attribute__((overloadable))
109ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines    rsGetDt(void);
110ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines
111ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines#endif
112