[go-nuts] Re: What is the reason behind time.Parse using a reference time?

2019-08-17 Thread Victor Giordano
I feel the same way, Jean.
I quite don't get it a the first, and still some times i require to look 
very well to distinguish the layout pattern for the string value beign 
parsed.


El lunes, 14 de abril de 2014, 10:19:29 (UTC-3), Jean de Klerk escribió:
>
> In java, we do things like new SimpleDateFormat("HH:mm:ss");. In php, 
> something like date_parse_from_format("j.n.Y H:iP", $date) or just 
> strtotime($date). In perl, we create a datetime parser with a pattern that 
> might look like pattern => '%B %d, %Y %I:%M %p %Z'. And so on and so on.
>
> However, in go we give it this ambiguous reference time, as in t, err := 
> time.Parse("2006-01-02 15:04", "2011-01-19 22:15").
>
> This seems odd to me. On first glance, I can't tell which is layout and 
> which is string, but we can move around that. Then, when using it, I'm 
> uncertain as to how to change formats without looking it up, I'm uncertain 
> as to whether or not my reference time is supposed to be just random 
> numbers or if I should specify things like 12-hour time vs 24-hour time, or 
> if post-1970 is different than pre-1970, and overall I don't understand the 
> reason why we choose arbitrary numbers instead of the aforementioned 
> conventions of things like Y-M-d.
>
> Thanks for any clarification on this. It's very clunky and tricky to use 
> at the moment, but I'm sure I'd understand it more if I more fully 
> understood the rational or what this approach solves that the other does 
> not.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/39391019-9c6c-4eb4-a7e1-28a86b6bab53%40googlegroups.com.


Re: [go-nuts] Re: What is the reason behind time.Parse using a reference time?

2019-08-16 Thread roger peppe
On Fri, 16 Aug 2019 at 01:24, Michael Baldry 
wrote:

> I agree with that. It is an odd choice, as I've never seen any other
> library use a reference date like that - there may be many but in 20 years,
> I've not seen one.
>
> I think your argument about Parse is valid, but in most cases, you'll be
> passing in a variable for the date you are parsing and the format will be
> in a constant, so you'd be more likely to have something like 
> time.Parse(myTimeFormat,
> request.birthday) or something.
>
> It's useful to remember the reference time has a pattern, but the MST, 12
> hour clock and it not being in a common order (day month, then year later)
> makes it less obvious, it is essentially: 01/02 03:04:05PM '06 -0700,
> that fact is obscured when parsing in common formats.
>

To me, that's the only significant flaw in this way of doing things. I can
never remember the order. I believe it should have been defined in
most-significant to least-significant order (same order as RFC3339), but
unfortunately it's too late for that now.


> On Thu, Aug 15, 2019 at 5:28 AM  wrote:
>
>> I think "2006-01-02 15:04" is a good idea, but have bad practice.
>> you cannot understand this code directly. then it is easy to write wrong
>> code like: time.Parse("1970-01-01 00:00", "2011-01-19 22:15")
>>
>> On Monday, April 14, 2014 at 9:19:29 PM UTC+8, Jean de Klerk wrote:
>>>
>>> In java, we do things like new SimpleDateFormat("HH:mm:ss");. In php,
>>> something like date_parse_from_format("j.n.Y H:iP", $date) or just
>>> strtotime($date). In perl, we create a datetime parser with a pattern that
>>> might look like pattern => '%B %d, %Y %I:%M %p %Z'. And so on and so on.
>>>
>>> However, in go we give it this ambiguous reference time, as in t, err :=
>>> time.Parse("2006-01-02 15:04", "2011-01-19 22:15").
>>>
>>> This seems odd to me. On first glance, I can't tell which is layout and
>>> which is string, but we can move around that. Then, when using it, I'm
>>> uncertain as to how to change formats without looking it up, I'm uncertain
>>> as to whether or not my reference time is supposed to be just random
>>> numbers or if I should specify things like 12-hour time vs 24-hour time, or
>>> if post-1970 is different than pre-1970, and overall I don't understand the
>>> reason why we choose arbitrary numbers instead of the aforementioned
>>> conventions of things like Y-M-d.
>>>
>>> Thanks for any clarification on this. It's very clunky and tricky to use
>>> at the moment, but I'm sure I'd understand it more if I more fully
>>> understood the rational or what this approach solves that the other does
>>> not.
>>>
>> --
>> 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.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/5d3a4adf-2b4c-4a4f-896e-85206da552a5%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Michael
>
>
>
> www.brightbits.co.uk
>
> Company number: 08133555
> Registered in England
> Registered office: 22 Finwell Road, Rainham, Kent, ME8 7PY
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAMQ_qVpHRvq2ukN0964hR64tJoLUNiN4vZLjrg%3DJswb%3D%3D7QK1Q%40mail.gmail.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAJhgaciE45RsZ6ebss20bCbA-mhhbEbCJZxxervTOZTQ5BbXqw%40mail.gmail.com.


Re: [go-nuts] Re: What is the reason behind time.Parse using a reference time?

2019-08-16 Thread Wojciech S. Czarnecki
On Thu, 15 Aug 2019 07:52:24 +0100
Michael Baldry  wrote:

> It's useful to remember the reference time has a pattern, 
> but the MST, 12 hour clock and it not being in a common order

There is no such thing as "common order" of date/time notation.
This notation is a part of the local culture. The Go format pattern happens
to be the "most natural" — though just for its birthplace (United States).

> (day month, then year later)
Thats natural for a big part of Europe and a chunk of Africa.

> it is essentially: 01/02 03:04:05PM '06 -0700, that
> fact is obscured when parsing in common formats.

Hope this helps :)

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20190816103949.6a7ff8c6%40zuzia.


Re: [go-nuts] Re: What is the reason behind time.Parse using a reference time?

2019-08-15 Thread Michael Baldry
I agree with that. It is an odd choice, as I've never seen any other
library use a reference date like that - there may be many but in 20 years,
I've not seen one.

I think your argument about Parse is valid, but in most cases, you'll be
passing in a variable for the date you are parsing and the format will be
in a constant, so you'd be more likely to have something like
time.Parse(myTimeFormat,
request.birthday) or something.

It's useful to remember the reference time has a pattern, but the MST, 12
hour clock and it not being in a common order (day month, then year later)
makes it less obvious, it is essentially: 01/02 03:04:05PM '06 -0700, that
fact is obscured when parsing in common formats.

On Thu, Aug 15, 2019 at 5:28 AM  wrote:

> I think "2006-01-02 15:04" is a good idea, but have bad practice.
> you cannot understand this code directly. then it is easy to write wrong
> code like: time.Parse("1970-01-01 00:00", "2011-01-19 22:15")
>
> On Monday, April 14, 2014 at 9:19:29 PM UTC+8, Jean de Klerk wrote:
>>
>> In java, we do things like new SimpleDateFormat("HH:mm:ss");. In php,
>> something like date_parse_from_format("j.n.Y H:iP", $date) or just
>> strtotime($date). In perl, we create a datetime parser with a pattern that
>> might look like pattern => '%B %d, %Y %I:%M %p %Z'. And so on and so on.
>>
>> However, in go we give it this ambiguous reference time, as in t, err :=
>> time.Parse("2006-01-02 15:04", "2011-01-19 22:15").
>>
>> This seems odd to me. On first glance, I can't tell which is layout and
>> which is string, but we can move around that. Then, when using it, I'm
>> uncertain as to how to change formats without looking it up, I'm uncertain
>> as to whether or not my reference time is supposed to be just random
>> numbers or if I should specify things like 12-hour time vs 24-hour time, or
>> if post-1970 is different than pre-1970, and overall I don't understand the
>> reason why we choose arbitrary numbers instead of the aforementioned
>> conventions of things like Y-M-d.
>>
>> Thanks for any clarification on this. It's very clunky and tricky to use
>> at the moment, but I'm sure I'd understand it more if I more fully
>> understood the rational or what this approach solves that the other does
>> not.
>>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/5d3a4adf-2b4c-4a4f-896e-85206da552a5%40googlegroups.com
> 
> .
>


-- 
Michael



www.brightbits.co.uk

Company number: 08133555
Registered in England
Registered office: 22 Finwell Road, Rainham, Kent, ME8 7PY

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMQ_qVpHRvq2ukN0964hR64tJoLUNiN4vZLjrg%3DJswb%3D%3D7QK1Q%40mail.gmail.com.


Re: [go-nuts] Re: What is the reason behind time.Parse using a reference time?

2019-08-15 Thread Wojciech S. Czarnecki
On Wed, 14 Aug 2019 19:12:40 -0700 (PDT)
sp55aa@gmail.com wrote:
> What is the reason behind time.Parse using a reference time?

The rationale is that every position of the reference time can be
treated as an enum (of int) stating the exact meaning of the field:

01/02 03:04:05PM '06 -0700
1 2 3 4 5 6 7 :  M D h m s year zone/offset

You then use these enums to tell the parser where in *your* date/time
format to parse these fields are. These are accompanied by words of
"Mon"/"Monday" "Jan"/"January" to show parser that format use names.

Eg.  you may need the "06/01" ("year's last two digit / month") format to
extract dates off some monthly financial reports.
In other place you will use "__2/06" ("day-of-year/year") to parse
daily sales reports.

Read https://golang.org/pkg/time/#pkg-constants till it clicks in :)

This is as simple and brilliant as many other things in Go.
Just the docs are somewhat terse.

> I think "2006-01-02 15:04" is a good idea, but have bad practice.
> you cannot understand this code directly. then it is easy to write wrong 
> code like: time.Parse("1970-01-01 00:00", "2011-01-19 22:15")

With format placeholders other languages use code is less readable
until you memorize all of mnemonics. [ man date, look what %_I does mean].
In Go you need only to remember that month is a first member of
"month, day, hour, minutes, seconds, year, zone" sequence and you
can read/understand any of hundreds being in use date formats.

Hope this helps,

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20190815144747.65f16214%40zuzia.


[go-nuts] Re: What is the reason behind time.Parse using a reference time?

2019-08-14 Thread sp55aa . org
I think "2006-01-02 15:04" is a good idea, but have bad practice.
you cannot understand this code directly. then it is easy to write wrong 
code like: time.Parse("1970-01-01 00:00", "2011-01-19 22:15")

On Monday, April 14, 2014 at 9:19:29 PM UTC+8, Jean de Klerk wrote:
>
> In java, we do things like new SimpleDateFormat("HH:mm:ss");. In php, 
> something like date_parse_from_format("j.n.Y H:iP", $date) or just 
> strtotime($date). In perl, we create a datetime parser with a pattern that 
> might look like pattern => '%B %d, %Y %I:%M %p %Z'. And so on and so on.
>
> However, in go we give it this ambiguous reference time, as in t, err := 
> time.Parse("2006-01-02 15:04", "2011-01-19 22:15").
>
> This seems odd to me. On first glance, I can't tell which is layout and 
> which is string, but we can move around that. Then, when using it, I'm 
> uncertain as to how to change formats without looking it up, I'm uncertain 
> as to whether or not my reference time is supposed to be just random 
> numbers or if I should specify things like 12-hour time vs 24-hour time, or 
> if post-1970 is different than pre-1970, and overall I don't understand the 
> reason why we choose arbitrary numbers instead of the aforementioned 
> conventions of things like Y-M-d.
>
> Thanks for any clarification on this. It's very clunky and tricky to use 
> at the moment, but I'm sure I'd understand it more if I more fully 
> understood the rational or what this approach solves that the other does 
> not.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5d3a4adf-2b4c-4a4f-896e-85206da552a5%40googlegroups.com.