Fix nsTime to handle nsInt64 operations better

RESOLVED FIXED in mozilla1.8alpha3

Status

()

P2
normal
RESOLVED FIXED
16 years ago
14 years ago

People

(Reporter: dwitte, Assigned: Biesinger)

Tracking

Trunk
mozilla1.8alpha3
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

16 years ago
currently, nsTime has limited arithmetic abilities, and doesn't inherit from
nsInt64, so you can't do simple things like

nsTime(foo) / nsTime(bar)

or

nsTime(foo) / nsInt64(bar)

at the moment, these require horrible constructs like |nsInt64(nsTime(foo)) /
nsInt64(nsTime(bar))| if you have two nsTimes.

on a related topic, the types in prtime.h could use some extra helpers (->
wtc?). doing things like

nsTime(foo) / PR_USEC_PER_SEC

doesn't give you expected results, because the nsTime doesn't cast itself to
anything except PRTime, a.k.a PRInt64. so it's most definitely not
!HAS_LONG_LONG safe. since the PR_USEC_PER_SEC (and related) constants are
defined as UL, you need to wrap them with nsInt64() (not nsTime(), because it
can't cast from UL) to do "real" 64-bit ops. further, since they're UL, if
you're compiling on a machine that defines "long" as 64-bit, then you're asking
for a 64-bit unsigned ctor for nsInt64(), which doesn't exist.

so these convenience classes aren't too convenient, when I end up having to do
things like

nsInt64(PR_Now()) / nsInt64(long(PR_USEC_PER_SEC))

so at the very least, can we get some operators added to nsTime(), get a
PRUint64 ctor for nsInt64(), and get some nice nsInt64/nsTime compatible
convenience constants? perhaps we should be making nsTime inherit from nsInt64
instead...

Comment 1

16 years ago
-> alec.
Assignee: dougt → alecf

Comment 2

16 years ago
My mozilla 1.4b is already looking cramped.

patches accepted :)
Status: NEW → ASSIGNED
Priority: -- → P2
Target Milestone: --- → mozilla1.5alpha
Created attachment 151251 [details] [diff] [review]
patch

this should help... makes nsTime inherit from nsInt64
Assignee: alecf → cbiesinger
Attachment #151251 - Flags: superreview?(dougt)
Attachment #151251 - Flags: review?(bsmedberg)
Target Milestone: mozilla1.5alpha → mozilla1.8alpha2

Updated

14 years ago
Attachment #151251 - Flags: review?(bsmedberg) → review+
Target Milestone: mozilla1.8alpha2 → mozilla1.8beta

Comment 4

14 years ago
Comment on attachment 151251 [details] [diff] [review]
patch

looks fine.  

Anyone interested in moving this out of XPCOM and into mailnews -- the main
customer of this class?
Attachment #151251 - Flags: superreview?(dougt) → superreview+
Checking in nsTime.h;
/cvsroot/mozilla/xpcom/ds/nsTime.h,v  <--  nsTime.h
new revision: 3.11; previous revision: 3.10
done

dwitte wants to use this in cookie code afaik, so moving this into mailnews
would be out...
Status: ASSIGNED → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → FIXED
Target Milestone: mozilla1.8beta → mozilla1.8alpha3
You need to log in before you can comment on or make changes to this bug.