[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] mktime works ?



At 1:47 PM +0100 4/20/99, Berndt Wischnewski wrote:

} Hi ,
}
} I try to calculate the time difference in seconds of some time data with
} first mktime and then difftime like
}
} #!/usr/bin/perl
} use POSIX;
}
} $sec1 = 0;
} $min1 = 11;
} $hour1 = 10;
} $day1 = 1;
} $month1 = 0;
} $year1 = 99;
} $sec2 = 0;
} $min2 = 9;
} $hour2 = 11;
} $day2 = 1;
} $month2 = 0;
} $year2 = 99;
}
} $secs1 =  POSIX::mktime($sec1, $min1, $hour1, $day1, $year1);
} $secs2 =  POSIX::mktime($sec2, $min2, $hour2, $day2, $year2);
} $result = POSIX::difftime($secs1, $secs2);


When I run this, I get a usage complaint:

# Usage: POSIX::mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0,
isdst = 0).
File 'Untitled'; Line 17

Please make sure you test the scripts you post to the list so they can be
cut and pasted.

Fixing your script, making one slight modification , which is necessary
when dealing with time under MacPerl

$result = POSIX::difftime($secs1|0, $secs2|0);

and putting a print $result."\n"; at the end, I get

-3480

which looks right in my current decaffeinated state.

}
}
} but the result is always zero. Even the example from the POSIX.pod file
}    #Calendar time for December 12, 1995, at 10:30 am.
}    $time_t = POSIX::mktime( 0, 30, 10, 12, 11, 95 );
}    print "Date = ", POSIX::ctime($time_t);


print "Date = ", POSIX::ctime($time_t|0);

}
} returns:
}    Date = Fri Jan  1 00:00:00 1904

Date = Tue Dec 12 10:30:00 1995

The reason this is necessary is that Mac dates have been > 2^31 s past the
zero of time for a while.  You have to keep perl from interpreting this
number as a signed integer.  Using the noop '| 0' does this.


}
} which seams not very correct.
}
} Any idea?
}
} By
} Berndt Wischnewski
}
}
}
}
} ===== Want to unsubscribe from this list? ===== Send mail with body
}"unsubscribe" to macperl-request@macperl.org



-----
Paul J. Schinder
schinder@pobox.com

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org