<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>I'm still with Alexander on this. I see functions like total_X as
      basically putting one of the arguments directly in the function
      name - it should be `total_duration(units)`, not `total_units()`,
      because all of those functions do the same thing and only differ
      in the units they use.<br>
      <br>
      But Alexander's approach of "divide it by the base unit" is <i>even
        more general</i> than this, because it allows you to use
      non-traditional units like weeks (timedelta(days=7)) or "two-day
      periods" or whatever you want. If you use this idiom a lot and
      want a simple "calculate the total" function, this should suffice:<br>
      <br>
      def total_duration(td, *args, **kwargs):<br>
          return td / timedelta(*args, **kwargs)<br>
      <br>
      Then you can spell "x.total_microseconds()" as:<br>
      <br>
      total_duration(x, microseconds=1)<br>
      <br>
      Or you can write it like this:<br>
      <br>
      def total_duration(td, units='seconds'):<br>
          return td / timedelta(**{units: 1})<br>
      <br>
      In which case it would be spelled:<br>
      <br>
      total_duration(x, units='microseconds')<br>
      <br>
      I don't see there being any compelling reason to add a bunch of
      methods for a marginal (and I'd say arguable) gain in aesthetics.<br>
    </p>
    <div class="moz-cite-prefix">On 2/15/19 4:48 PM, Chris Barker via
      Python-Dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CALGmxE+_tC3LimrsMS4ROzYqQ24nJTnSyQRLBGd8kEzukEVQqA@mail.gmail.com">
      <div dir="ltr">
        <div dir="ltr">On Fri, Feb 15, 2019 at 11:58 AM Rob Cliffe via
          Python-Dev <<a href="mailto:python-dev@python.org"
            moz-do-not-send="true">python-dev@python.org</a>> wrote:<br>
        </div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote">
            <div> A function with "microseconds" in the name IMO
              misleadingly suggests that it has something closer to
              microsecond accuracy than a 1-second granularity.<br>
            </div>
          </blockquote>
          <div><br>
          </div>
          <div>it sure does, but `delta.total_seconds()` is a float, so
            ms accuracy is preserved.</div>
          <div><br>
          </div>
          <div>However, if you DO want a "timedelta_to_microseconds"
            function, it really should use the microseconds field in the
            timedelta object. I haven't thought it through, but it makes
            me nervous to convert to floating point, and then back again
            -- for some large values of timedelta some precision may be
            lost.</div>
          <div><br>
          </div>
          <div>Also:</div>
          <div><br>
          </div>
          <div>
            <blockquote type="cite">
              <div dir="ltr">
                <div dir="ltr">
                  <div>_MICROSECONDS_PER_SECOND = 1000000</div>
                </div>
              </div>
            </blockquote>
          </div>
          <div><br>
          </div>
          <div>really? why in the world would you define a constant for
            something that simple that can never change? (and probably
            isn't used in more than one place anyway</div>
          <div> </div>
          <div>As Alexander pointed out the canonical way to spell this
            would be:</div>
          <div><br>
          </div>
          <div>delta / timedelta(microseconds=1)</div>
          <div><br>
          </div>
          <div>but I think that is less than obvious to the usual user,
            so I think a:</div>
          <div><br>
          </div>
          <div>delta.total_microseconds()</div>
          <div><br>
          </div>
          <div>would be a reasonable addition.</div>
          <div><br>
          </div>
          <div>I know I use .totalseconds() quite a bit, and would not
            want to have to spell it:</div>
          <div><br>
          </div>
          <div>delta / timedelta(seconds=1)<br>
          </div>
          <div><br>
          </div>
          <div>(and can't do that in py2 anyway)</div>
          <div><br>
          </div>
          <div>-CHB</div>
          <div><br>
          </div>
        </div>
        -- <br>
        <div dir="ltr" class="gmail_signature"><br>
          Christopher Barker, Ph.D.<br>
          Oceanographer<br>
          <br>
          Emergency Response Division<br>
          NOAA/NOS/OR&R            (206) 526-6959   voice<br>
          7600 Sand Point Way NE   (206) 526-6329   fax<br>
          Seattle, WA  98115       (206) 526-6317   main reception<br>
          <br>
          <a href="mailto:Chris.Barker@noaa.gov" target="_blank"
            moz-do-not-send="true">Chris.Barker@noaa.gov</a></div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Python-Dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Python-Dev@python.org">Python-Dev@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/options/python-dev/paul%40ganssle.io">https://mail.python.org/mailman/options/python-dev/paul%40ganssle.io</a>
</pre>
    </blockquote>
  </body>
</html>