Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in Localtime #812

Closed
p5pRT opened this issue Nov 3, 1999 · 2 comments
Closed

bug in Localtime #812

p5pRT opened this issue Nov 3, 1999 · 2 comments

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Nov 3, 1999

Migrated from rt.perl.org#1740 (status was 'resolved')

Searchable as RT1740$

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Nov 3, 1999

From rbroeck@new-edc.nl

I found a problem using the function localtime. Executing the below script
will give me a wrong value for $mon (10 i.s.o. 11)​:

($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(time) ;
printf "$year/$mon/$day\n";
printf "$hour​:$min​:$sec\n";
printf "$]\n";

output​:

99/10/3
12​:12​:2
5.00503

using the functions date and time (MSDOS box under Windows NT 4)

Date​: wo 03-11-1999
time​: 12​:12​:02,32

Is this a bug in Perl ?

perl -V gives you​:

Summary of my perl5 (5.0 patchlevel 5 subversion 03) configuration​:
  Platform​:
  osname=MSWin32, osvers=4.0, archname=MSWin32-x86-object
  uname=''
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=undef useperlio=undef d_sfio=undef
  Compiler​:
  cc='cl.exe', optimize='-O2 -MD -DNDEBUG -TP -GX', gccversion=
  cppflags='-DWIN32'
  ccflags ='-O2 -MD -DNDEBUG -TP -GX -DWIN32 -D_CONSOLE -DNO_STRICT
-DHAVE_DES_FCRYPT -DPERL_OBJECT'
  stdchar='char', d_stdstdio=define, usevfork=false
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
  alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='link', ldflags ='-nologo -nodefaultlib -release -machine​:x86'
  libpth="C​:\Perl\lib\core"
  libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib
uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib
PerlCRT.lib
  libc=C​:\Perl\lib\CORE\PerlCRT.lib, so=dll, useshrplib=yes,
libperl=perlcore.lib
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release
-machine​:x86'

Characteristics of this binary (from libperl)​:
  Locally applied patches​:
  ActivePerl Build 519
  Built under MSWin32
  Compiled at Aug 12 1999 09​:50​:30
  @​INC​:
  c​:/Perl/lib
  c​:/Perl/site/lib
  .
Rob Van den Broeck
New EDC BV

e-mail​: mailto​:rbroeck@​new-edc.nl
www : http​://www.new-edc.nl

This email is confidential and intended solely for the use of the individual
to whom it is addressed. Any views or opinions expressed are solely those of
the author and do not necessarily represent those of New Europe Data Consult
BV (New EDC consists of two business units, EDC and OA). If you are not the
intended recipient, be advised that you have received this email in error
and that any use, dissemination, forwarding, printing, or copying of this
email is strictly prohibited.
If you have received this email in error please notify the New EDC I&S
Department by email to postmaster@​europe-data-consult.nl, or alternatively
by telephone on +31 (0) 10 4132399

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Nov 3, 1999

From [Unknown Contact. See original ticket]

Rob van den Broeck <rbroeck@​new-edc.nl> writes​:

I found a problem using the function localtime. Executing the below script
will give me a wrong value for $mon (10 i.s.o. 11)​:

($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(time) ;
printf "$year/$mon/$day\n";
printf "$hour​:$min​:$sec\n";
printf "$]\n";

output​:

99/10/3
12​:12​:2
5.00503

=item localtime EXPR

Converts a time as returned by the time function to a 9-element array
with the time analyzed for the local time zone. Typically used as
follows​:

  # 0 1 2 3 4 5 6 7 8
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  localtime(time);

All array elements are numeric, and come straight out of a struct tm. In
particular this means that C<$mon> has the range C<0..11> and C<$wday> has
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the range C<0..6> with sunday as day C<0>. Also, C<$year> is the number
of years since 1900, that is, C<$year> is C<123> in year 2023, and I<not>
simply the last two digits of the year.

If EXPR is omitted, uses the current time (C<localtime(time)>).

In scalar context, returns the ctime(3) value​:

  $now_string = localtime; # e.g., "Thu Oct 13 04​:54​:34 1994"

This scalar value is B<not> locale dependent, see L<perllocale>, but
instead a Perl builtin. Also see the C<Time​::Local> module, and the
strftime(3) and mktime(3) function available via the POSIX module. To get
somewhat similar but locale dependent date strings, set up your locale
environment variables appropriately (please see L<perllocale>) and try for
example​:

  use POSIX qw(strftime);
  $now_string = strftime "%a %b %e %H​:%M​:%S %Y", localtime;

Note that the C<%a> and C<%b>, the short forms of the day of the week and
the month of the year, may not necessarily be three characters wide.

--
Russ Allbery (rra@​stanford.edu) <URL​:http​://www.eyrie.org/~eagle/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.