114 Commits

Author SHA1 Message Date
dearblue cc1db2d117 Remove unnecessary 'stdio.h'; ref #4947
'stdio.h' is included in 'mruby.h' ('mrbconf.h').

However, keep 'stdio.h' used by mruby-test.
2020-03-08 21:42:09 +09:00
Yukihiro "Matz" Matsumoto 0301d8a89b Fix integer boundary check before float to time_t casting. 2020-02-12 11:54:32 +09:00
KOBAYASHI Shuji b493229a23 Silence GCC warning in time.c on Travis CI
Silence the following warnings:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:260:55: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if ((MRB_INT_MAX > MRB_TIME_MAX && i > 0 && i > MRB_TIME_MAX) ||
                                                  ^
  ```
2019-12-31 21:52:20 +09:00
KOBAYASHI Shuji e6033e00fe Auto detect MRB_TIME_T_UINT 2019-12-05 21:40:15 +09:00
KOBAYASHI Shuji ea1911d23f Silence Clang warning with MRB_INT64 and MRB_32BIT in time.c
Silence the following warnings:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:871:15: warning: result of comparison of constant 9223372036854775807 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) {
        ~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:871:40: warning: result of comparison of constant -9223372036854775808 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) {
                                 ~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:887:16: warning: result of comparison of constant 9223372036854775807 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) {
        ~~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:887:42: warning: result of comparison of constant -9223372036854775808 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) {
                                ~~~~~~~~ ^ ~~~~~~~~~~~
  ```
2019-12-03 22:50:50 +09:00
KOBAYASHI Shuji 6973539005 Silence Clang warning with MRB_INT32 and MRB_64BIT in time.c
Silence the following warning:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:258:60: warning: result of comparison of constant -9223372036854775808 with expression of type 'mrb_int' (aka 'int') is always false [-Wtautological-constant-out-of-range-compare]
        if ((mrb_time_int)i > MRB_TIME_MAX || MRB_TIME_MIN > i) {
                                              ~~~~~~~~~~~~ ^ ~
  ```
2019-12-02 20:00:36 +09:00
Yukihiro "Matz" Matsumoto 529a336966 Fixed a bug in mruby-time with NO_GETTIMEOFDAT. 2019-10-10 20:46:12 +09:00
dearblue eb2f34719d Fix MRB_WITHOUT_FLOAT reversal; fix #4598 2019-09-25 22:55:41 +09:00
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in
my environment than before the introduction of new specifiers/modifiers
(5116789a) with this change.

  ------------+-------------------+-------------------+--------
   BINARY     | BEFORE (5116789a) |   AFTER (This PR) |  RATIO
  ------------+-------------------+-------------------+--------
   mruby      |      593416 bytes |      593208 bytes | -0.04%
   libmruby.a |      769048 bytes |      767264 bytes | -0.23%
  ------------+-------------------+-------------------+--------

BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613,
so I put it back.
2019-08-05 13:18:50 +09:00
dearblue 07308a2fc9 Suppress compiler warnings for mruby-time; fix #4600
Warnings:

- If `MRB_TIME_T_UINT` is defined, the compiler issues a warning with an
  integer comparison of different signs.
- It is mentioned that the `usec` variable passed to the
  `mrb_to_time_t()` function may not be initialized
2019-08-03 10:35:39 +09:00
KOBAYASHI Shuji 5116789aa0 Fix UTC offset representation in Time#to_s on some environments; ref #4604
Use own implementation to calculate UTC offset on Visual Studio 2015 or
earlier or MinGW because `strftime("%z")` on these environments does not
conform C99.
2019-07-31 20:34:27 +09:00
Sutou Kouhei effae4ae55 Fix Time#to_s encoding on Windows
strftime() on Windows returns locale encoding time zone for "%z" even
if MSDN says "%z" is "The offset from UTC in ISO 8601 format; no
characters if time zone is unknown" in MSDN:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=vs-2019

So we need to convert encoding of string from strftime().
2019-07-29 18:16:21 +09:00
dearblue fda5c0c073 Fix the lack of precision for Time; ref d74355061
- `Time.local` and `Time.utc` are able to use with `MRB_INT16 + MRB_WITHOUT_FLOAT`.

  - `time_t` is converted directly from the Ruby object.

  - `time + sec` and` time - sec` are not affected by the precision of `mrb_float`.

    Similarly, calculations are possible with `MRB_INT16 + MRB_WITHOUT_FLOAT`.
2019-07-27 21:25:18 +09:00
dearblue 1467c14adc Fix mruby-time with MRB_WITHOUT_FLOAT; ref d74355061 2019-07-27 14:42:37 +09:00
Yukihiro "Matz" Matsumoto d74355061b Fix mruby-time to work with MRB_WITHOUT_FLOAT; ref #4576
As a side effect, `mrb_time_at()` now takes `mrb_int` instead of
`double` as time arguments.
2019-07-22 21:34:37 +09:00
Yukihiro "Matz" Matsumoto 87d1b2a910 Improve conflict error message of Time and Math; ref #4576 2019-07-22 20:21:30 +09:00
dearblue c96b517ea2 Error needed/conflicts configuration
The purpose is to clarify the error if there is a needed/conflicts
configuration at compile time.
2019-07-14 00:29:17 +09:00
KOBAYASHI Shuji 240bbc39e1 Fix the order of "expected" and "actual" in mruby-time test 2019-05-24 21:02:22 +09:00
Yukihiro "Matz" Matsumoto 4bc48d0b76 Refactor time.c regarding memory allocation. 2019-05-16 22:49:27 +09:00
KOBAYASHI Shuji edf4b33c61 Refine Time#(to_s|inspect)
For the following reasons:

- Ruby compatibility.
- Add UTC offset (time zone informations was not included by #4433).
- More readable.

Example:

  Before this patch:

    p Time.gm(2003,4,5,6,7,8,9)        #=> Sat Apr  5 06:07:08 2003
    p Time.local(2013,10,28,16,27,48)  #=> Mon Oct 28 16:27:48 2013

  After this patch:

    p Time.gm(2003,4,5,6,7,8,9)        #=> 2003-04-05 06:07:08 UTC
    p Time.local(2013,10,28,16,27,48)  #=> 2013-10-28 16:27:48 +0900

Implementation:

I use `strftime(3)` because UTC offset can be added and program size become
smaller than the other implementations (using `sprintf(3)`, self conversion
etc) in my environment.
2019-05-14 22:50:36 +09:00
KOBAYASHI Shuji a2616db4dc Fix Time#(asctime|ctime) according to ISO Ruby
- A leading charactor for day is space.
- Time zone does not included.

Before this patch:

  Time.gm(1982,3,4,5,6,7).asctime  #=> "Thu Mar 04 05:06:07 UTC 1982"

After this patch:

  Time.gm(1982,3,4,5,6,7).asctime  #=> "Thu Mar  4 05:06:07 1982"
2019-05-13 19:46:26 +09:00
KOBAYASHI Shuji 2c2584138a Fix missing assertions in mruby-time test 2019-05-12 20:25:11 +09:00
Yukihiro "Matz" Matsumoto ca0dcbb226 Free struct mrb_time before error; fix #4308
To avoid memory leak from `time_update_datetime`.
2019-03-02 14:13:06 +09:00
takkaw 995a329bf4 fix Time about carry-up and carry-down 2019-01-26 23:19:53 +09:00
take-cheeze 3e7a3a0a15 Export Time creation API 2019-01-08 20:26:39 +09:00
dearblue 0bfeefad2a Suppress _MSC_VER warns for mingw32 2018-12-23 17:36:06 +09:00
Yukihiro "Matz" Matsumoto 624b126fb6 Added Android Hack to time.c.
Android bionic defines `TIME_UTC` but does not provide `timespec_get`.
2018-12-19 13:12:30 +09:00
Yukihiro "Matz" Matsumoto 3498a787ba Merge pull request #3936 from ken-mu/uint
mruby-time: support time_t is uint
2018-01-30 12:42:49 +09:00
ken-mu a1b71b64b3 mruby-time: remove ifdef for mktime error handling 2018-01-29 09:43:43 +00:00
ken-mu 6a2c0c6e2a mruby-time: support time_t is uint 2018-01-28 03:03:20 +00:00
Yukihiro "Matz" Matsumoto 3ff56a8e55 Time.new(1969,12,31,23,59,59) may or may not faile; ref #3932
On some platform and timezone it is a valid time spec.
2018-01-24 21:42:25 +09:00
ken-mu d398cd47d7 mruby-time: remove test case less than Dec 31 23:59:58 1969 2018-01-21 02:47:17 +00:00
ken-mu a1f36316d2 mruby-time: Fix mruby specific timegm() cannot return minus 2018-01-20 13:09:58 +00:00
Tomasz Dąbrowski be81504770 fix: mrbgems\mruby-time\src\time.c(641): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 0848407ee5 fix: mrbgems\mruby-time\src\time.c(372): warning C4244: 'function': conversion from 'mrb_int' to 'double', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dabrowski e00b48be4a change DISABLE_STDIO to MRB_DISABLE_STDIO in mruby-time/time.c 2017-09-25 13:11:20 +02:00
Yukihiro "Matz" Matsumoto bad807e7f0 Use floor() to implement round() on WIN32 platform.
This change was suggested by Akira Kakuto.
2017-07-13 20:32:34 +09:00
Yukihiro "Matz" Matsumoto 70e99d6b57 Define round() only on WIN32 platform; fix #3741 2017-07-13 00:09:31 +09:00
Yukihiro "Matz" Matsumoto 92dcfbaab3 Add explicit cast from double to long. 2017-04-25 17:43:03 +09:00
Yukihiro "Matz" Matsumoto 88cd807379 Avoid use of snprintf() when DISABLE_STDIO is set; fix #3632
ref #3492 #3515 #3517
2017-04-25 10:41:50 +09:00
Clayton Smith dc4fba28c5 Correctly handle large negative usec value. 2017-04-03 14:22:26 -04:00
Yukihiro "Matz" Matsumoto 77331d127b Unify else clause style 2017-04-03 16:56:27 +09:00
Yukihiro "Matz" Matsumoto 8d9d7c929e Improve Time.new() performance using division; fix #3561 2017-04-01 13:03:34 +09:00
ksss db3573e0bf Should raise FloatDomainError 2017-03-29 11:59:19 +09:00
ksss 397f1fc946 Fix infinity loop
And some cases should raise FloatDomainError
2017-03-28 10:58:18 +09:00
Yukihiro "Matz" Matsumoto c4491e477b Validate tm values before timegm(); close #3368
This issue was reported by https://hackerone.com/volc
2017-01-09 10:42:11 +09:00
Yukihiro "Matz" Matsumoto bc1259de3b add explicit casts 2017-01-02 17:48:44 +09:00
Yukihiro "Matz" Matsumoto 07167b8f5e Initialize potentially uninitialized variable tsec. 2017-01-01 00:47:45 +09:00
Yukihiro "Matz" Matsumoto 9a962ed2c3 Raise an exception in time_update_datetime().
The function used to return NULL on error, but not checked in the
caller site.
2016-12-06 10:27:35 +09:00
Yukihiro "Matz" Matsumoto 3d9aa463f7 Add NULL checks for Time data retrieval 2016-11-27 20:47:20 +09:00