Re: [go-nuts] Re: Unexpected behavior of %+02d in Sprintf() and friends

2018-08-29 Thread Eric Raymond
On Wednesday, August 29, 2018 at 7:57:23 AM UTC-4, Borman, Paul wrote:
>
> Is it possible you used the format string “+%02d” vs “%+02d”?  The first 
> will give you the +00 you expected while the second is +0, as discussed.
>

Alas, no.  Here's the line from my test program:

fmt.Printf("%s: %+02d %02d\n", runtime.Version(), 0, 0)

In the original context where I saw the behavior, I was generating [+-]hhmm 
strings corresponding to timezone offsets. The sign in the output could not 
be fixed in the format; it had to be derived from the offset.




-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Unexpected behavior of %+02d in Sprintf() and friends

2018-08-29 Thread 'Borman, Paul' via golang-nuts
Is it possible you used the format string “+%02d” vs “%+02d”?  The first will 
give you the +00 you expected while the second is +0, as discussed.

On Aug 29, 2018, at 6:53 AM, Eric Raymond 
mailto:e...@thyrsus.com>> wrote:

On Tuesday, August 28, 2018 at 4:49:02 PM UTC-4, peterGo wrote:
"Width is specified by an optional decimal number immediately preceding the 
verb. If absent, the width is whatever is necessary to represent the value. "

https://golang.org/pkg/fmt/

Width is two.

Thanks for the clarification.  May I recommend appending to that sentence 
"(including the leading sign, if any, even if the sign is forced by a + 
modifier)"?

I still think i saw apparently inconsistent behavior.  I'm still writing unit 
tests involving date conversions, so I'm going to try to reproduce this and 
turn in an actionable report.

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Unexpected behavior of %+02d in Sprintf() and friends

2018-08-29 Thread Eric Raymond
On Tuesday, August 28, 2018 at 4:49:02 PM UTC-4, peterGo wrote:
>
> "Width is specified by an optional decimal number immediately preceding 
> the verb. If absent, the width is whatever is necessary to represent the 
> value. "
>
> https://golang.org/pkg/fmt/
>
> Width is two.
>

Thanks for the clarification.  May I recommend appending to that sentence 
"(including the leading sign, if any, even if the sign is forced by a + 
modifier)"?

I still think i saw apparently inconsistent behavior.  I'm still writing 
unit tests involving date conversions, so I'm going to try to reproduce 
this and turn in an actionable report.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Unexpected behavior of %+02d in Sprintf() and friends

2018-08-28 Thread peterGo
Eric,

For example,

package main

import (
"fmt"
"runtime"
)

func main() {
// Correctly prints "+0 00\n" as +00 00
fmt.Printf("%s: %+03d %02d\n", runtime.Version(), 0, 0)
}

Output:

go1.10.3: +00 00

Playground: https://play.golang.org/p/Pt2-YJfQvEo

Widths three and two.

Peter

On Tuesday, August 28, 2018 at 4:49:02 PM UTC-4, peterGo wrote:
>
> Eric,
>
> "Width is specified by an optional decimal number immediately preceding 
> the verb. If absent, the width is whatever is necessary to represent the 
> value. "
>
> https://golang.org/pkg/fmt/
>
> Width is two.
>
> Peter
>
> On Tuesday, August 28, 2018 at 12:09:26 PM UTC-4, Eric Raymond wrote:
>>
>> Under Go 1.10.1, feeding an 0 value to a %+02d specifier sometimes 
>> yields  "+0", not "+00". The attached tiny Go program may reproduce this 
>> behavior.  I say "may" because I first observed it in a series of unit 
>> tests of date format conversions - in different format strings %+02d 
>> expanded differently.  I haven't found a pattern to this, or I'd report it. 
>> On my system this program, at least, has repeatable behavior.
>>
>> If this behavior were consistent, I'm not sure it would be a bug. It's 
>> possible that the sign is supposed to be counted as part of the number 
>> width; if so, it's an interesting question whether this is the right thing 
>> when explicit sign is forced by +.  The documentation is unclear.
>>
>> The apparent inconsistency worries me.  There may be some state in the 
>> form,at-interpretation code that is not always tracked correctly.
>>
>> In accordance with the Contribution Guidelines, I'm tossing  the question 
>> out here for a sanity check before throwing it on the bugtracker.  Have 
>> there been any similar reports?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Unexpected behavior of %+02d in Sprintf() and friends

2018-08-28 Thread peterGo
Eric,

"Width is specified by an optional decimal number immediately preceding the 
verb. If absent, the width is whatever is necessary to represent the value. 
"

https://golang.org/pkg/fmt/

Width is two.

Peter

On Tuesday, August 28, 2018 at 12:09:26 PM UTC-4, Eric Raymond wrote:
>
> Under Go 1.10.1, feeding an 0 value to a %+02d specifier sometimes yields  
> "+0", not "+00". The attached tiny Go program may reproduce this behavior.  
> I say "may" because I first observed it in a series of unit tests of date 
> format conversions - in different format strings %+02d expanded 
> differently.  I haven't found a pattern to this, or I'd report it. On my 
> system this program, at least, has repeatable behavior.
>
> If this behavior were consistent, I'm not sure it would be a bug. It's 
> possible that the sign is supposed to be counted as part of the number 
> width; if so, it's an interesting question whether this is the right thing 
> when explicit sign is forced by +.  The documentation is unclear.
>
> The apparent inconsistency worries me.  There may be some state in the 
> form,at-interpretation code that is not always tracked correctly.
>
> In accordance with the Contribution Guidelines, I'm tossing  the question 
> out here for a sanity check before throwing it on the bugtracker.  Have 
> there been any similar reports?
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.