1- /* Copyright 2015 Samsung Electronics Co., Ltd.
2- * Copyright 2015 University of Szeged.
1+ /* Copyright 2015-2016 Samsung Electronics Co., Ltd.
2+ * Copyright 2015-2016 University of Szeged.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2424#include " fdlibm-math.h"
2525#include " lit-char-helpers.h"
2626
27+ #include < time.h>
28+
2729#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN
2830
2931/* * \addtogroup ecma ECMA
@@ -445,13 +447,14 @@ ecma_date_week_day (ecma_number_t time) /**< time value */
445447ecma_number_t __attr_always_inline___
446448ecma_date_local_tza ()
447449{
448- /*
449- * FIXME:
450- * Get the real system time. ex: localtime_r, gmtime_r, daylight on Linux
451- * Introduce system macros at first.
452- */
453- TODO (" Implement time functions in jerry-libc." );
454- return ECMA_NUMBER_ZERO;
450+ struct timezone tz;
451+
452+ if (gettimeofday (NULL , &tz) != 0 )
453+ {
454+ return ecma_raise_type_error (" gettimeofday failed" );
455+ }
456+
457+ return tz.tz_minuteswest * -60000 ;
455458} /* ecma_date_local_tza */
456459
457460/* *
@@ -470,13 +473,14 @@ ecma_date_daylight_saving_ta (ecma_number_t time) /**< time value */
470473 return time; /* time is NaN */
471474 }
472475
473- /*
474- * FIXME:
475- * Get the real system time. ex: localtime_r, gmtime_r, daylight on Linux
476- * Introduce system macros at first.
477- */
478- TODO (" Implement time functions in jerry-libc." );
479- return ECMA_NUMBER_ZERO;
476+ struct timezone tz;
477+
478+ if (gettimeofday (NULL , &tz) != 0 )
479+ {
480+ return ecma_raise_type_error (" gettimeofday failed" );
481+ }
482+
483+ return tz.tz_dsttime ;
480484} /* ecma_date_daylight_saving_ta */
481485
482486/* *
@@ -1062,7 +1066,7 @@ ecma_date_value_to_string (ecma_number_t datetime_number) /**< datetime */
10621066 /*
10631067 * Character length of the result string.
10641068 */
1065- const uint32_t result_string_length = 33 ;
1069+ const uint32_t result_string_length = 34 ;
10661070
10671071 lit_utf8_byte_t character_buffer[result_string_length];
10681072 lit_utf8_byte_t *dest_p = character_buffer;
@@ -1082,10 +1086,19 @@ ecma_date_value_to_string (ecma_number_t datetime_number) /**< datetime */
10821086 dest_p = ecma_date_value_to_string_common (dest_p, datetime_number);
10831087
10841088 int32_t time_zone = (int32_t ) (ecma_date_local_tza () + ecma_date_daylight_saving_ta (datetime_number));
1085- *dest_p++ = (time_zone >= 0 ) ? LIT_CHAR_PLUS : LIT_CHAR_MINUS;
1089+ if (time_zone >= 0 )
1090+ {
1091+ *dest_p++ = LIT_CHAR_PLUS;
1092+ }
1093+ else
1094+ {
1095+ *dest_p++ = LIT_CHAR_MINUS;
1096+ time_zone = -time_zone;
1097+ }
10861098
1087- dest_p = ecma_date_value_number_to_bytes (dest_p, time_zone / 60 , 2 );
1088- dest_p = ecma_date_value_number_to_bytes (dest_p, time_zone % 60 , 2 );
1099+ dest_p = ecma_date_value_number_to_bytes (dest_p, time_zone / 3600000 , 2 );
1100+ *dest_p++ = LIT_CHAR_COLON;
1101+ dest_p = ecma_date_value_number_to_bytes (dest_p, time_zone % 3600000 , 2 );
10891102
10901103 JERRY_ASSERT ((uint32_t ) (dest_p - character_buffer) == result_string_length);
10911104
0 commit comments