Hello,
Thanks for the contrarian - or maybe yours is the mainstream 
opinion. For the record, 2006 is NOT the Go birthday year - it's 2009
according to Wikipedia [1]. It's just a "menomic device", that is,
2006 fits into the 0-1-2-3-4-5-6-7 series.
Cheers. Prost.
PS: One upside of the Go lang style is that it's unambiguous and also
easy to code up.
Here's all the ruby code from the date_by_example gem [2]:
class GoStyleDateByExampleFormatter
attr_accessor :reference
def initialize(reference)
@reference = reference
@format_string = nil
end
FORMATS = {
".000000000" => ".9N",
"-07:00:00" => "%::z",
".000000" => ".%6N",
"January" => "%B",
"JANUARY" => "%^B",
"Monday" => "%A",
"MONDAY" => "%^A",
"-07:00" => "%:z",
"-7000" => "%z",
"2006" => "%Y",
".000" => ".%L",
"002" => "%j",
"Jan" => "%b",
"JAN" => "%^b",
"Mon" => "%a",
"MON" => "%^a",
"MST" => "%Z",
"15" => "%H",
"06" => "%y",
"01" => "%m",
"02" => "%d",
"03" => "%I",
"PM" => "%p",
"pm" => "%P",
"04" => "%M",
"05" => "%S",
"1" => "%-m",
"2" => "%-e",
"3" => "%l"}.freeze
FORMAT_MATCHER = Regexp.union(FORMATS.keys)
def format_string
@format_string ||= reference.gsub(FORMAT_MATCHER, FORMATS)
end
def format(date)
date.strftime(format_string)
end
end
[1]: Go (programming language) - Wikipedia
[2] date_by_example/lib/date_by_example/example_formatter.rb at master · noelrappin/date_by_example · GitHub
···
El lun., 17 feb. 2020 a las 18:19, Marvin Gülker (<post+rubytalk@guelker.eu>) escribió:
>In Golang you always MUST use the Monday, January 2, 2006
>15:04:05 -7:00 reference date that you can supposedly learn and keep
>in memory by using the 0-1-2-3-4-5-6-7 trick. 0 = Monday, 1 = January,
>2 = Day 2, 3 = Hour 15, 4 = Minute 4, 5 = Second 5, 6 = Year 2006, 7 =
>Timezone -7:00 (MST). Anyone has any opinions on the Go Lang Reference
>Date Style? Pro or contra?
I always found Golang's way to specify date formatting highly confusing.
All other languages I work with use placeholders, and placeholders are
what one is used to with printf() and similar functions. Golang breaks
consistency here in my opinion. When I first read Golang's docs about
the topic, I had a hard time to understand what they want from me. Not
using placeholders came over as completely arcane and entirely unusual.
Since I have no real intention to memoise Golang's release year (2006,
appearently), I always need to pull up the reference documentation to
get the correct date. The most important strftime placeholders are easy
to learn, because they map to the first letter of the English name for
the component, but even in case I forget them, I can fire up the
strftime(3) manpage much faster than I can browse to golang.org's
reference docs.
To me, it appears as if Golang solved a problem here that never existed.
--
Blog: https://mg.guelker.eu
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>