Difference between revisions of "Stamp2UnixInt"
Jump to navigation
Jump to search
Void Singer (talk | contribs) m (fixed byte costs) |
m (<lsl> tag to <source>) |
||
Line 13: | Line 13: | ||
* MONO: 1024 bytes | * MONO: 1024 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">integer uStamp2UnixInt( list vLstStp ){ | ||
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902; | integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902; | ||
integer vIntRtn; | integer vIntRtn; | ||
Line 34: | Line 34: | ||
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Minimal Version</h3> | <h3>Minimal Version</h3> | ||
Line 41: | Line 41: | ||
* MONO: 1024 bytes | * MONO: 1024 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">integer uStamp2UnixInt( list vLstStp ){ | ||
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902; | integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902; | ||
integer vIntRtn; | integer vIntRtn; | ||
Line 64: | Line 64: | ||
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Safe(er) Version</h3> | <h3>Safe(er) Version</h3> | ||
Line 71: | Line 71: | ||
* MONO: 1536 bytes | * MONO: 1536 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">integer uStamp2UnixInt( list vLstStp ){ | ||
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902; | integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902; | ||
integer vIntRtn; | integer vIntRtn; | ||
Line 94: | Line 94: | ||
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
}} | }} | ||
Line 107: | Line 107: | ||
|content= | |content= | ||
* Input list elements past the first six are ignored | * Input list elements past the first six are ignored | ||
* Input format is compattible with: < | * Input format is compattible with: <source lang="lsl2">llParseString2List( llGetTimestamp(), ["-", "T", ":", "."], [] )</source>and<source lang="lsl2">llParseString2List( llGetDate(), ["-"], [] )</source> | ||
}} | }} | ||
Latest revision as of 14:35, 22 January 2015
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials | User-Defined Functions | Void's User Page |
User-Defined Function: integer uStamp2UnixInt( list vLstStp );
Returns an integer that is the Unix time code represented by the input list
- vLstStmp: source time stamp list of format [Y, M, D, h, m, s]
Unsafe Version
(Missing day/month or bad values not handled)
- LSO: 465 bytes
- MONO: 1024 bytes
integer uStamp2UnixInt( list vLstStp ){
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
integer vIntRtn;
if (vIntYear >> 31 | vIntYear / 136){
vIntRtn = 2145916800 * (1 | vIntYear >> 31);
}else{
integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
(((vIntYear + 2) & 3) > 0) * (vIntMnth > 1) +
(~-llList2Integer( vLstStp, 2 )) ) +
llList2Integer( vLstStp, 3 ) * 3600 +
llList2Integer( vLstStp, 4 ) * 60 +
llList2Integer( vLstStp, 5 );
}
return vIntRtn;
}
/*//-- Anti-License Text --//*/
/*// Contributed Freely to the Public Domain without limitation. //*/
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
/*//-- --//*/
Minimal Version
(Safely supports missing Day/Month)
- LSO: 505 bytes
- MONO: 1024 bytes
integer uStamp2UnixInt( list vLstStp ){
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
integer vIntRtn;
if (vIntYear >> 31 | vIntYear / 136){
vIntRtn = 2145916800 * (1 | vIntYear >> 31);
}else{
integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
integer vIntDays = ~-llList2Integer( vLstStp, 2 );
vIntMnth += !~vIntMnth;
vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
(((vIntYear + 2) & 3) > 0) * (vIntMnth > 1) +
vIntDays + !~vIntDays ) +
llList2Integer( vLstStp, 3 ) * 3600 +
llList2Integer( vLstStp, 4 ) * 60 +
llList2Integer( vLstStp, 5 );
}
return vIntRtn;
}
/*//-- Anti-License Text --//*/
/*// Contributed Freely to the Public Domain without limitation. //*/
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
/*//-- --//*/
Safe(er) Version
(Supports missing Day/Month and bad inputs are capped)
- LSO: 640 bytes
- MONO: 1536 bytes
integer uStamp2UnixInt( list vLstStp ){
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
integer vIntRtn;
if (vIntYear >> 31 | vIntYear / 136){
vIntRtn = 2145916800 * (1 | vIntYear >> 31);
}else{
integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
integer vIntDays = ~-llList2Integer( vLstStp, 2 );
vIntMnth = llAbs( (vIntMnth + !~vIntMnth) % 12 );
vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
(((vIntYear + 2) & 3) > 0) * (vIntMnth > 1) +
llAbs( (vIntDays + !~vIntDays) % 31 ) ) +
llAbs( llList2Integer( vLstStp, 3 ) % 24 ) * 3600 +
llAbs( llList2Integer( vLstStp, 4 ) % 60 ) * 60 +
llAbs( llList2Integer( vLstStp, 5 ) % 60 );
}
return vIntRtn;
}
/*//-- Anti-License Text --//*/
/*// Contributed Freely to the Public Domain without limitation. //*/
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
/*//-- --//*/
Caveats
- Time codes before the year 1902 or past the end of 2037 are capped to the first second of 1902 and 2038 respectively
Notes
- Input list elements past the first six are ignored
- Input format is compattible with: and
llParseString2List( llGetTimestamp(), ["-", "T", ":", "."], [] )
llParseString2List( llGetDate(), ["-"], [] )