caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* .-
@ 2004-12-24 10:04 Anastasia Gornostaeva
  2004-12-24 10:53 ` [Caml-list] .- Benjamin Geer
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Anastasia Gornostaeva @ 2004-12-24 10:04 UTC (permalink / raw)
  To: Caml-list

Hello.

open Unix

let _ =
   let curr_time = time () in
   let curr_tm = gmtime curr_time in
   let new_time, _ = mktime {curr_tm with tm_hour = curr_tm.tm_hour+1} in
   let diff = new_time -. curr_time in
      Printf.printf "%f\n%f\n%f\n"
	 curr_time
	 new_time
	 diff


gives an negative result -7200.000000. Why? 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] .-
  2004-12-24 10:04 .- Anastasia Gornostaeva
@ 2004-12-24 10:53 ` Benjamin Geer
  2004-12-24 11:25   ` skaller
  2004-12-24 11:07 ` Alexander Fuchs
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Benjamin Geer @ 2004-12-24 10:53 UTC (permalink / raw)
  To: caml-list; +Cc: Anastasia Gornostaeva

On Friday 24 December 2004 10:04, Anastasia Gornostaeva wrote:
> gives an negative result -7200.000000. Why?

I just tried it and got this result:

        Objective Caml version 3.08.1

# #load "unix.cma" ;;
# open Unix

  let _ =
     let curr_time = time () in
     let curr_tm = gmtime curr_time in
     let new_time, _ = mktime {curr_tm with tm_hour = curr_tm.tm_hour+1} in
     let diff = new_time -. curr_time in
        Printf.printf "%f\n%f\n%f\n"
           curr_time
           new_time
           diff  ;;
1103885443.000000
1103889043.000000
3600.000000
- : unit = ()

Ben


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] .-
  2004-12-24 10:04 .- Anastasia Gornostaeva
  2004-12-24 10:53 ` [Caml-list] .- Benjamin Geer
@ 2004-12-24 11:07 ` Alexander Fuchs
  2004-12-24 11:27   ` Anastasia Gornostaeva
  2004-12-24 11:14 ` Julien Cristau
  2004-12-24 11:19 ` skaller
  3 siblings, 1 reply; 9+ messages in thread
From: Alexander Fuchs @ 2004-12-24 11:07 UTC (permalink / raw)
  To: Anastasia Gornostaeva; +Cc: Caml-list

Anastasia Gornostaeva wrote:
> open Unix
> 
> let _ =
>    let curr_time = time () in
>    let curr_tm = gmtime curr_time in
>    let new_time, _ = mktime {curr_tm with tm_hour = curr_tm.tm_hour+1} in
>    let diff = new_time -. curr_time in
>       Printf.printf "%f\n%f\n%f\n"
> 	 curr_time
> 	 new_time
> 	 diff
> 
> 
> gives an negative result -7200.000000. Why?

Form the manual:

gmtime : Assumes UTC (Coordinated Universal Time), also known as GMT.

mktime : The tm argument is interpreted in the local time zone.

So, actually you compare GMT with your local time zone, which in my case 
(Germany) returns 0 for the above example.


Try localtime instead of gmtime:

localtime : Assumes the local time zone.


	Alex


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] .-
  2004-12-24 10:04 .- Anastasia Gornostaeva
  2004-12-24 10:53 ` [Caml-list] .- Benjamin Geer
  2004-12-24 11:07 ` Alexander Fuchs
@ 2004-12-24 11:14 ` Julien Cristau
  2004-12-24 11:19 ` skaller
  3 siblings, 0 replies; 9+ messages in thread
From: Julien Cristau @ 2004-12-24 11:14 UTC (permalink / raw)
  To: caml-list

On 24/12/2004-11:10, Anastasia Gornostaeva wrote:

> Hello.
> 
> open Unix
> 
> let _ =
>    let curr_time = time () in
>    let curr_tm = gmtime curr_time in
>    let new_time, _ = mktime {curr_tm with tm_hour = curr_tm.tm_hour+1} in
>    let diff = new_time -. curr_time in
>       Printf.printf "%f\n%f\n%f\n"
> 	 curr_time
> 	 new_time
> 	 diff
> 
> 
> gives an negative result -7200.000000. Why? 
> 
Probably because Unix.mktime's argument is interpreted in the local time 
zone (as explained in unix.mli). You probably want to call 
Unix.localtime instead of Unix.gmtime.

HTH,
Julien


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] .-
  2004-12-24 10:04 .- Anastasia Gornostaeva
                   ` (2 preceding siblings ...)
  2004-12-24 11:14 ` Julien Cristau
@ 2004-12-24 11:19 ` skaller
  2004-12-24 12:14   ` Anastasia Gornostaeva
  3 siblings, 1 reply; 9+ messages in thread
From: skaller @ 2004-12-24 11:19 UTC (permalink / raw)
  To: Anastasia Gornostaeva; +Cc: Caml-list

On Fri, 2004-12-24 at 21:04, Anastasia Gornostaeva wrote:
> Hello.
> 
> open Unix
> 
> let _ =
>    let curr_time = time () in
>    let curr_tm = gmtime curr_time in
>    let new_time, _ = mktime {curr_tm with tm_hour = curr_tm.tm_hour+1} in
>    let diff = new_time -. curr_time in
>       Printf.printf "%f\n%f\n%f\n"
> 	 curr_time
> 	 new_time
> 	 diff
> 
> 
> gives an negative result -7200.000000. Why? 

Because you live in Russia not London.

gmtime is adjusting for your timezone. Instead of 1 hour,
you're getting -2 hours. So I am going to guess you live
in a GMT+3 hour timezone .. so that's Western Russia,
perhaps Moscow?

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] .-
  2004-12-24 10:53 ` [Caml-list] .- Benjamin Geer
@ 2004-12-24 11:25   ` skaller
  2004-12-24 11:34     ` Benjamin Geer
  0 siblings, 1 reply; 9+ messages in thread
From: skaller @ 2004-12-24 11:25 UTC (permalink / raw)
  To: Benjamin Geer; +Cc: caml-list, Anastasia Gornostaeva

On Fri, 2004-12-24 at 21:53, Benjamin Geer wrote:

> 
>   let _ =
>      let curr_time = time () in
>      let curr_tm = gmtime curr_time in
>      let new_time, _ = mktime {curr_tm with tm_hour = curr_tm.tm_hour+1} in
>      let diff = new_time -. curr_time in
>         Printf.printf "%f\n%f\n%f\n"
>            curr_time
>            new_time
>            diff  ;;
> 1103885443.000000
> 1103889043.000000
> 3600.000000
> - : unit = ()

-9 hours? Sounds like USA...

Here's me:

1103887404.000000
1103851404.000000
-36000.000000

That's Eastern Australia.
[should be +10 hours.. hmmm]

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] .-
  2004-12-24 11:07 ` Alexander Fuchs
@ 2004-12-24 11:27   ` Anastasia Gornostaeva
  0 siblings, 0 replies; 9+ messages in thread
From: Anastasia Gornostaeva @ 2004-12-24 11:27 UTC (permalink / raw)
  To: Caml-list

On Fri, Dec 24, 2004 at 12:07:35PM +0100, Alexander Fuchs wrote:

> Form the manual:
> 
> gmtime : Assumes UTC (Coordinated Universal Time), also known as GMT.
> 
> mktime : The tm argument is interpreted in the local time zone.
> 
> So, actually you compare GMT with your local time zone, which in my case 
> (Germany) returns 0 for the above example.
> 
> 
> Try localtime instead of gmtime:
> 
> localtime : Assumes the local time zone.
> 
Great, thank you. Now it works as expected.

ermine


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] .-
  2004-12-24 11:25   ` skaller
@ 2004-12-24 11:34     ` Benjamin Geer
  0 siblings, 0 replies; 9+ messages in thread
From: Benjamin Geer @ 2004-12-24 11:34 UTC (permalink / raw)
  To: skaller; +Cc: caml-list

On Friday 24 December 2004 11:25, skaller wrote:
> > 3600.000000
> > - : unit = ()
>
> -9 hours? Sounds like USA...

I'm in London; I expect that's 3600 seconds, i.e. the one-hour difference 
specified in the program.  (It only worked because my local time zone is GMT, 
for the reasons others have given.)

Ben


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] .-
  2004-12-24 11:19 ` skaller
@ 2004-12-24 12:14   ` Anastasia Gornostaeva
  0 siblings, 0 replies; 9+ messages in thread
From: Anastasia Gornostaeva @ 2004-12-24 12:14 UTC (permalink / raw)
  To: Caml-list

On Fri, Dec 24, 2004 at 10:19:12PM +1100, skaller wrote:

> Because you live in Russia not London.
> 
> gmtime is adjusting for your timezone. Instead of 1 hour,
> you're getting -2 hours. So I am going to guess you live
> in a GMT+3 hour timezone .. so that's Western Russia,
> perhaps Moscow?

yes Moscow, thanks :)

ermine


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-12-24 12:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-24 10:04 .- Anastasia Gornostaeva
2004-12-24 10:53 ` [Caml-list] .- Benjamin Geer
2004-12-24 11:25   ` skaller
2004-12-24 11:34     ` Benjamin Geer
2004-12-24 11:07 ` Alexander Fuchs
2004-12-24 11:27   ` Anastasia Gornostaeva
2004-12-24 11:14 ` Julien Cristau
2004-12-24 11:19 ` skaller
2004-12-24 12:14   ` Anastasia Gornostaeva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).