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

Add a NodaConstants.TicksPerMicrosecond constant #333

Closed
GoogleCodeExporter opened this issue Mar 15, 2015 · 4 comments
Closed

Add a NodaConstants.TicksPerMicrosecond constant #333

GoogleCodeExporter opened this issue Mar 15, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

What situation does this request make simpler?

I am retrofitting my project's code to use NodaTime.  We interface with WinPcap 
whose packet header uses the timeval structure to represent its timestamp.  We 
convert this to a DateTime as follows:

new DateTime(Constants.Time.TicksAtUnixEpoch             + // 
621,355,968,000,000,000
             Constants.Time.TicksPerSecond      * tv_sec + //              10,000,000
             Constants.Time.TicksPerMicrosecond * tv_usec, //                      10
             DateTimeKind.Utc);

Obviously, I want to replace the DateTime with NodaTime.Instant.  To do this, I 
use the following:

new Instant(NodaTime.NodaConstants.TicksPerSecond             * tv_sec +  // 
10,000,000
            NodaTime.NodaConstants.TicksPerMillisecond / 1000 * tv_usec); //     10,000

I would prefer the following:

new Instant(NodaTime.NodaConstants.TicksPerSecond      * tv_sec +  // 10,000,000
            NodaTime.NodaConstants.TicksPerMicrosecond * tv_usec); //         10


Can you provide a straw-man example of what you'd want the API to look
like?

        //
        // Summary:
        //     A constant for the number of ticks in a microsecond. The value of this constant
        //     is 10.
        public const long TicksPerMicrosecond = 10;


Original issue reported on code.google.com by MatthewN...@gmail.com on 16 Oct 2014 at 6:14

@GoogleCodeExporter
Copy link
Author

I'm not sure about this... I can see the appeal, but then for consistency we 
should also have all kinds of other constants for microseconds (microseconds 
per second etc).

A simple workaround is clearly for you to have the constant in your own class 
somewhere - it's not like it's really Noda-specific, so I don't think you need 
to worry about it changing :)

NodaConstants is already expanding quite a bit for 2.0 where we move to 
nanosecond precision, and this will add to that. On the other hand, there are 
relatively few downsides of adding the constants (and we do already have 
milliseconds)... I'll think about it a bit more.

Original comment by jonathan.skeet on 16 Oct 2014 at 6:19

@GoogleCodeExporter
Copy link
Author

Yes, defining the constant on my end solves the problem, and that's what I'll 
continue to do for now.  Still, the elegance of having domain-specific logic 
grouped together in the same class/namespace is a very appealing hobgoblin to 
this foolish seeker of consistency.  :)  Here's to hoping it gets in.  Thanks 
for your consideration, Jon.

Original comment by MatthewN...@gmail.com on 16 Oct 2014 at 6:40

@GoogleCodeExporter
Copy link
Author

Original comment by malcolm.rowe on 19 Feb 2015 at 1:14

  • Added labels: Milestone-2.0-consider, Type-Enhancement

@jskeet
Copy link
Member

jskeet commented Oct 16, 2017

No other requests for this in 2.5 years - closing for now.

@jskeet jskeet closed this as completed Oct 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants