UuLinuxTime
Revision as of 05:28, 29 August 2011 by Kaluura Boa (talk | contribs)
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials | User-Defined Functions | Kaluura's User Page |
User-Defined Function: integer uuLinuxTime( integer year, integer mon, integer day, integer hour, integer min, integer sec );
Returns an integer that is the Unix time code representing the input date
- year
- mon: month
- day
- hour: hours (0 to 23)
- min: minutes
- sec: seconds
(This function was converted to LSL from Linux kernel's source: /usr/src/*/kernel/time.c)
It excepts a date/time in UTC. ([Coordinated Universal Time])
- PST = UTC - 8 hours
- PDT = UTC - 7 hours
<lsl>// Contributed Freely to the Public Domain without limitation. // 2011 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] // Kaluura Boa [ https://wiki.secondlife.com/wiki/User:Kaluura_Boa ] // integer uuLinuxTime(integer year, integer mon, integer day, integer hour, integer min, integer sec) {
mon -= 2; if (mon <= 0) { mon += 12; --year; } return ((((year/4 - year/100 + year/400 + (367*mon)/12 + day) + year*365 - 719499)*24 + hour)*60 + min)*60 + sec;
}
default {
state_entry() { llOwnerSay("1970-01-01 00:00:00 --> " + (string)uuLinuxTime(1970, 1, 1, 0, 0, 0)); llOwnerSay("2005-03-18 02:58:31 --> " + (string)uuLinuxTime(2005, 3, 18, 1, 58, 31)); llOwnerSay("2009-02-13 23:31:30 --> " + (string)uuLinuxTime(2009, 2, 13, 23, 31, 30)); llOwnerSay("2038-01-19 03:14:07 --> " + (string)uuLinuxTime(2038, 1, 19, 3, 14, 7));
}
}
</lsl>Notes
- This function does not check if the input values are valid.
- Valid dates are from 1970-01-01 00:00:00 to 2038-01-19 03:14:07.
- Beyond this date, the returned value will be negative since LSL integers are always signed.
- It will also restart to zero for any date beyond 2106-02-07 06:28:15.