[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-datetime
Subject:    localtime and timelocal
From:       Alexey Salmin <alexey.salmin () gmail ! com>
Date:       2010-01-21 6:41:58
Message-ID: 87a8dc11001202241p3e1a4391k8109471d2be89465 () mail ! gmail ! com
[Download RAW message or body]

[Please CC me since I'm not subscribed to the list]

Hello! I think this question have already appeared on this list but
unfortunately I didn't find any reference.
I'm just curious: why localtime is a built-in function but timelocal
is in a core module?
AFAICT there're different approaches to the question of
built-in/library functions:
1) Common consideration is that inverse function should be on the same level
Not used here, localtime and timelocal are on different levels.
2) Function, which is a wrapper to a system call - built-in, otherwise
- library.
Certainly not used here: localtime(3) is in Standard C Library. There
are time(2) and gettimeofday(2) calls in POSIX and functions like
localtime or asctime are built on top of them.
3) Function, which is a wrapper to a system call or Standard C Library
- built-in, otherwise - library.
At first blush it seems that this approach is not used here either:
there are localtime(3) and mktime(3) functions both in the Standart C
Library. But reading the docs
(http://perldoc.perl.org/Time/Local.html#IMPLEMENTATION) leaded me to
a conclusion that timelocal doesn't use mktime(3). At this point it
all started to make sense: localtime - wrapper to a localtime(3) from
C library - built-in, timelocal - complicated function - library.
But that puts another question: WHY timelocal doesn't use mktime?
There are also different possible reasons I can imagine:
1) mktime is not supported everywhere? Not likely actually. It is in
Standart C Library since C89. Taking in account that early perl
versions appeared somewhere around 1987 I don't think that it is the
real reason.
2) timelocal guarantee 100% compatibliry with localtime. May be
mktime(3) is not completely compatible to localtime(3)? Haven't heard
about such issues. Anybody can comment on that?


I'll be glad to get any additional information/opinions/comments.

Alexey
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic