Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Timestamp List_format_to_Unix_time_code  

List_format_to_Unix_time_code

List_format_to_Unix_time_code

Category: Timestamp
By : Void Singer
Created: 2010-02-01 Edited: 2010-02-01
Worlds: Second Life

the Zip file

Download all files for List_format_to_Unix_time_code
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. List_format_to_Unix_time_code_1.lsl
1 /*//-- Notes:
2 Time codes before the year 1902 or past the end of 2037
3 are capped to the first second of 1902 or 2038 respectively
4
5 Input format is [Y, M, D, h, m, s] in numerals. Strings are converted.
6 Elements past the end are safely ignored, for compatibility with
7 llParseString2List( llGetTimestamp(), ["-", "T", ":", "."], [] )
8 Short [Y, M, D] format is supported for compatibility with
9 llParseString2List( llGetDate(), ["-"], [] )
10 //*/
11
12 //-- unsafe version (missing day/month or bad values not handled)
13 integer uStamp2UnixInt( list vLstStp ){
14 integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
15 integer vIntRtn;
16 if(vIntYear >> 31 | vIntYear / 136){
17 vIntRtn = 2145916800 * (1 | vIntYear >> 31);
18 }else{
19 integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
20 vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
21 vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
22 ((vIntYear & 3) > 0) * (vIntMnth > 1) +
23 (~-llList2Integer( vLstStp, 2 )) ) +
24 llList2Integer( vLstStp, 3 ) * 3600 +
25 llList2Integer( vLstStp, 4 ) * 60 +
26 llList2Integer( vLstStp, 5 );
27 }
28 return vIntRtn;
29 }
30
31 //-- this version safely supports missing Day/Month
32 integer uStamp2UnixInt( list vLstStp ){
33 integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
34 integer vIntRtn;
35 if(vIntYear >> 31 | vIntYear / 136){
36 vIntRtn = 2145916800 * (1 | vIntYear >> 31);
37 }else{
38 integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
39 integer vIntDays = ~-llList2Integer( vLstStp, 2 );
40 vIntMnth += !~vIntMnth;
41 vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
42 vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
43 ((vIntYear & 3) > 0) * (vIntMnth > 1) +
44 vIntDays + !~vIntDays ) +
45 llList2Integer( vLstStp, 3 ) * 3600 +
46 llList2Integer( vLstStp, 4 ) * 60 +
47 llList2Integer( vLstStp, 5 );
48 }
49 return vIntRtn;
50 }
51
52 //-- Double Safe (as previous, with bad input capping)
53 integer uStamp2UnixInt( list vLstStp ){
54 integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
55 integer vIntRtn;
56 if(vIntYear >> 31 | vIntYear / 136){
57 vIntRtn = 2145916800 * (1 | vIntYear >> 31);
58 }else{
59 integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
60 integer vIntDays = ~-llList2Integer( vLstStp, 2 );
61 vIntMnth = llAbs( (vIntMnth + !~vIntMnth) % 12 );
62 vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
63 vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
64 ((vIntYear & 3) > 0) * (vIntMnth > 1) +
65 llAbs( (vIntDays + !~vIntDays) % 31 ) ) +
66 llAbs( llList2Integer( vLstStp, 3 ) % 24 ) * 3600 +
67 llAbs( llList2Integer( vLstStp, 4 ) % 60 ) * 60 +
68 llAbs( llList2Integer( vLstStp, 5 ) % 60 );
69 }
70 return vIntRtn;
71 }
72 /*//-- Anti-License Text --//*/
73 /*// Contributed Freely to the Public Domain without limitation. //*/
74 /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/
75 /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
76 /*//--

Back to the Best Free Tools in Second Life and OpenSim.