Skip to content

Commit 0a23e23

Browse files
committed
Merge pull request #846 from mfuentesg/master
use str_format_time function on user_info command
2 parents 3a898a4 + 681b8e7 commit 0a23e23

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

json-tg.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,23 @@ void json_pack_peer_type (json_t *res, tgl_peer_id_t id) {
3232
}
3333
}
3434

35+
int str_format_time(long when, char* string)
36+
{
37+
struct tm *tm = localtime ((void *)&when);
38+
return sprintf (string, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
39+
}
3540

3641
void json_pack_user (json_t *res, tgl_peer_t *P) {
3742
if (P->user.first_name) {
3843
assert (json_object_set (res, "first_name", json_string (P->user.first_name)) >= 0);
3944
}
45+
46+
if (P->user.status.when) {
47+
static char s[20];
48+
str_format_time(P->user.status.when, s);
49+
assert (json_object_set (res, "when", json_string (s)) >= 0);
50+
}
51+
4052
if (P->user.last_name) {
4153
assert (json_object_set (res, "last_name", json_string (P->user.last_name)) >= 0);
4254
}
@@ -436,12 +448,6 @@ json_t *json_pack_read (struct tgl_message *M) {
436448
return res;
437449
}
438450

439-
int str_format_time(long when, char* string)
440-
{
441-
struct tm *tm = localtime ((void *)&when);
442-
return sprintf (string, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
443-
}
444-
445451
json_t *json_pack_user_status (struct tgl_user *U) {
446452
json_t *res = json_object ();
447453
assert (json_object_set (res, "user", json_pack_peer (U->id)) >= 0);

0 commit comments

Comments
 (0)