-
-
Save fjcero/2223967 to your computer and use it in GitHub Desktop.
Python | |
====== | |
>>> status_id = int(184846323277770752) | |
>>> timestamp = (status_id >> 22) | |
>>> print timestamp | |
44070797748 | |
>>> timestamp = (status_id >> 22) + 1288834974657 | |
>>> print timestamp | |
1332905772405 | |
>>> import time | |
>>> print time.ctime(timestamp/1000) | |
Wed Mar 28 00:36:12 2012 | |
PHP | |
=== | |
php > $status_id = '184846323277770752'; | |
php > $timestamp = ($status_id >> 22); | |
php > echo $timestamp; | |
511 | |
php > $timestamp = ($status_id >> 22) + '1288834974657'; | |
php > echo $timestamp; | |
1288834975168 | |
The integer value of var on success, or 0 on failure. Empty arrays return 0, non-empty arrays return 1. | |
The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807. | |
Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply. |
Ah, pero estoy en 64 bits
Darwin Lightie.local 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64
Si, eso, estás en 64bits :)
No probe en AWS. Quizas haya suerte.
Una solución sucia:
$ cat tweet_time.py
import sys
import time
status_id = int(sys.argv[1])
timestamp = (status_id>>22) + 1288834974657
print time.ctime(timestamp/1000)
$ php -a
php > echo python tweet_time.py 184846323277770752
;
Wed Mar 28 00:36:12 2012
Ah, en 64 bits hasta el bitwise anda. Todavia no resolví la parte de la conversión de tiempos. Supongo que date() alcanza, indeed:
php > $timestamp = 1332905772405/1000;
php > echo date('Y-m-d', $timestamp);
2012-03-28
El quid es obtener un $timestamp valido, con un INT valido.
php > print PHP_INT_MAX;
2147483647
Para leer con menos sueño:
http://stackoverflow.com/questions/300840/force-php-integer-overflow
php > $status_id = (int) '184846323277770752';
php > var_dump($status_id);
int(184846323277770752)
php > $timestamp = ($status_id >> 22);
php > echo $timestamp;
44070797748
php > $timestamp = ($status_id >> 22) + '1288834974657';
php > echo $timestamp;
1332905772405