diff options
author | Karl Williamson <khw@cpan.org> | 2020-03-14 14:33:05 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-03-18 18:08:57 -0600 |
commit | 0bd9a4dd60d8f4d8a8858b9017c1f861838b56b5 (patch) | |
tree | 6193408efde17f69332f53f02c1e0e1ea9e9e028 /time64.c | |
parent | 6358af1715b0184076504f68f4610f4d97c57114 (diff) | |
download | perl-0bd9a4dd60d8f4d8a8858b9017c1f861838b56b5.tar.gz |
time64.c: Refactor Perl_localtime64_r()
There are two main cases in Perl_localtime64_r(), call them A and B.
Prior to this commit, it was structured
if (A) {
codeA
return;
}
codeB
return;
The problem this commit solves is that there is common stuff in codeA
and codeB that will now only be specified once. Currently that common
stuff is minimal, and so acceptable, but the next few commits will make
the common stuff more complex, so making it be only once is helpful.
Diffstat (limited to 'time64.c')
-rw-r--r-- | time64.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -476,15 +476,8 @@ struct TM *Perl_localtime64_r (const Time64_T *time, struct TM *local_tm) safe_time = (time_t)*time; TIME64_TRACE1("Using system localtime for %lld\n", *time); - - LOCALTIME_R(&safe_time, &safe_date); - - S_copy_little_tm_to_big_TM(&safe_date, local_tm); - assert(S_check_tm(local_tm)); - - return local_tm; } - + else { if( Perl_gmtime64_r(time, &gm_tm) == NULL ) { TIME64_TRACE1("gmtime64_r returned null for %lld\n", *time); return NULL; @@ -501,6 +494,8 @@ struct TM *Perl_localtime64_r (const Time64_T *time, struct TM *local_tm) } safe_time = (time_t)S_timegm64(&gm_tm); + } + if( LOCALTIME_R(&safe_time, &safe_date) == NULL ) { TIME64_TRACE1("localtime_r(%d) returned NULL\n", (int)safe_time); return NULL; @@ -508,6 +503,8 @@ struct TM *Perl_localtime64_r (const Time64_T *time, struct TM *local_tm) S_copy_little_tm_to_big_TM(&safe_date, local_tm); + if (! use_system) { + local_tm->tm_year = orig_year; if( local_tm->tm_year != orig_year ) { TIME64_TRACE2("tm_year overflow: tm_year %lld, orig_year %lld\n", @@ -545,6 +542,8 @@ struct TM *Perl_localtime64_r (const Time64_T *time, struct TM *local_tm) if( !IS_LEAP(local_tm->tm_year) && local_tm->tm_yday == 365 ) local_tm->tm_yday--; + } + assert(S_check_tm(local_tm)); return local_tm; |