12 ms·
Go Date Format
- f2f 12y agoTIL that the hardest thing to do in computer science is to learn something new and different.
- bdotdub 12y agoI think the real lesson here is developers have a warped sense of time and would rather spend relatively much more time building a website to solve a problem than it would just to learn it
- dap 12y agoThat's right. There's already so much that engineers have to keep in mind when programming. The less new stuff (particularly arbitrary stuff) people have to keep in mind when building software, IME, the more likely the software is to be correct. That's why designers typically leverage existing conventions when possible rather than invent new ones. It greatly reduces complexity to bind a newish idea (e.g., a new syntax) onto something they already understand well. This is good because complexity is among the biggest enemies of robust software.
- kalleboo 12y agoNot so much learn but to retain. Working in a web stack you end up having to juggle something like 5 languages at once (Your server language + SQL + HTML + CSS + JavaScript) not to mention these "micro-languages" like time formatting, imgsrc strings, etc. This is why ORMs and things like node.js are popular - to reduce the burden of dealing with a bunch of different languages.
- svisser 12y agoStrangely the non-profanity version http://flippinggodateformat.com http://flippinggodateformat.com still has profanity.
- bdotdub 12y agoHa my bad. Fixed :)
- nkozyra 12y ago> Ha my bad. Fucked :) Fucked it for you.
- bdotdub 12y agoThanks for flipping it ;)
- heezo 12y agoThanks.
- wging 12y agoIt still has profanity, in the form of a link to http://fuckinggodateformat.com/ http://fuckinggodateformat.com/ :) Personally I see no problem with this being a WONTFIX. I wouldn't even have built the flipping thing in the first place. (I might have built the fucking thing, though.)
- vruiz 12y agoWhile I got also shocked at first by Go's time formatting, is by far the easiest to learn and memorize once you get it. The argument from the issue https://github.com/golang/go/issues/444 https://github.com/golang/go/issues/444 > It would be much easier to port preexisting code if you could just copy your time formats over. It's not really much of an argument, since transforming the sprintf format to Go is a trivial as printing an specific date.
- DAddYE 12y agoNah, parsing a date is a thing that you do usually (depends on your job) like 1 every 2/3 months at best. Every time I have to pick up the docs because Is day the 1st or month the 1st? Ms and Ns which number? Timezone? I think that the decision of golang to use this way is really unfortunate and yet more lazy than people that don't want to learn yet another (useless) thing.
- chimeracoder 12y ago> While I got also shocked at first by Go's time formatting, is by far the easiest to learn and memorize once you get it. I completely agree. I've used strftime and the like for years, and I still can't remember %m vs %M without thinking twice about it, at which point I usually just look at the docs to make sure I'm not making a mistake. By contrast, as soon as I learned the "trick"[0] behind the canonical date in Go, I had it committed to memory, and I haven't needed to look it up once since. YMMV, but personally, I'd much rather write "Jan" when I want a three-character month and "January" when I want a full month than try to remember that the former is %a and the latter is %A (...or is it the other way around? Time to check... again!) [0] http://golang.org/pkg/time/#pkg-constants http://golang.org/pkg/time/#pkg-constants
- deathanatos 12y ago> I still can't remember %m vs %M without thinking twice about it The time component is "%H:%M:%S" — it's all capitals, and I always think "her majesty's ship" when I type it for some odd reason. At any rate, that's how I remember it. Once I work out that time component, then the date falls into place: "%m-%d-%Y". But yes, strftime's formatting strings aren't memorable. (I'm also a server-side engineer, so I active try to avoid formatting dates into anything other than ISO-8601…)
- elmin 12y agoI, for one, deeply appreciate any project which isn't afraid to do things differently when they decide there's a better way. I see it similar to iOS not supporting Flash, or Angular 2.0 rethinking things. You can't change everything, but it's what you do differently that gives your project value.
- deleted 12y ago[deleted]
- deleted 12y ago[deleted]
- dap 12y agoSure, but date formatting? That's where Go is going to differentiate itself? Even though it still uses a C-like format string? This seems like exactly the kind of area where leveraging the existing conventions would be a no-brainer.
- pb2au 12y agoIt isn't the format string syntax that is the problem that they're trying to solve. I see this as being an iterative, backwards-incompatible improvement on the existing format convention. Changes in convention don't have to be all or nothing.
- deleted 12y ago[deleted]
- deleted 12y ago[deleted]
- guard-of-terra 12y agoI was wondering why they didn't borrow java SimpleDateFormat But then I noticed they decided to tackle the dd-MM-yyyyTHH:mm:ss problem AKA crazy case. Which is kind of noble.
- Htsthbjig 12y agoThere are two thing I don't like in IT: 1- Using names for software that is confusing with names of real things that have nothing to do with it, like Cocoa for a user interface library and so many others. 2- Using the terms a two year old will use when she discovers it is funny and gets attention just for saying dirty words. In this particular case, this combines both in one. The first thing I thought was: This will have something to do with dating and having casual sex or something. Then you discover that no, it has nothing to do with it, it is just a two year old like mindset creating a "funny"(for him) name for their pet project.
- coldtea 12y ago>Using the terms a two year old will use when she discovers it is funny and gets attention just for saying dirty words. So, preffering what a prude 50 year old from some place with a strong puritan culture would want to see.
- Htsthbjig 12y agoFor me puritan culture is exactly what makes someone believe this is funny when it is not. A kid does not find funny what it is not "tabu" or "forbidden".
- striking 12y ago> having casual sex What? Also, have you tried http://flippinggodateformat.com/ http://flippinggodateformat.com/ ? It seems they took your considerations into account.
- BenDaglish 12y agoPersonally, when I first read the spec. for time.Format, I thought "well how bleedin' sensible is that?!" The only thing that annoys me is that it isn't in ISO order (I'd have preferred 2001-02-03 14:05:06 ), but all that you need to remember is "2006-01" and the rest just falls naturally into place. I've seen a couple of "complaints" about this over the last few days, and I just don't understand what the problem is. It's logical and neat.
- ustolemyname 12y agoISO ordering would make expressing time in AM/PM ambiguous, i.e. the format string "2:05PM".
- lifthrasiir 12y ago12:34:56 2007-08-09 would work equally, though. (EDIT: oops, no.)
- ustolemyname 12y agoHow do I cleanly express single digit minutes? The format string "4 minutes after 12", is unique, but it's not clear that I could turn "34" into "4". Similar for the hour (12 is now 2). That would also break the "Print this exact time in the format you're currently using" method of creating a compatible time format string.
- fafner 12y agoThat's not ISO format though.
- tjradcliffe 12y agoBut why would you want to? FSM intended us to use ISO-8601 dates and nothing else. If you disagree, I'll meet you on 18/06/12 at 2:04 to discuss the issue, although you have no way of knowing what date or time that string actually refers to. We have a perfectly good, unambigious date and time format. It's true that many users are deeply committed to ambiguous formats, but we should at the very least be trying to dissuade them from using them by making ISO formats the default.
- pbreit 12y agoI appreciate the "flipping" version but why such an obnoxiously immature primary domain?
- larrys 12y agoI agree with you (and upvoted you). The reasons is simple to express emotion and obviously to get attention. A little bit of history. I don't remember exactly when in the 90's it changed but at a certain point there were actually certain words banned from being used in domain registrations.
- vhost- 12y ago>I don't remember exactly when in the 90's it changed but at a certain point there were actually certain words banned from being used in domain registrations. Isn't that censorship? Maybe that's why it changed...
- mholt 12y agoSame sentiment here. In fact, "flipping" makes more sense, even literally, since it's like "flipping the date format" into Go's.
- vacri 12y agoTo be honest, I find your tutting about vulgarity in someone's cheat-sheet to be more obnoxious than the swearing.
- ciupicri 12y agoI thought that children were the ones not allowed to curse :-)
- Normati 12y agoIt's unfortunate that languages are so monolithic. You want to make a language that does concurrency differently and you end up having to design date format strings! Sad that we still don't have any kind of common libraries or whatever it might take to just do this a couple of times and let language designers pick and choose the preexisting components they want.
- enneff 12y agoIf you use Go and want strftime then use one of the available libraries: http://godoc.org/?q=strftime http://godoc.org/?q=strftime
- adwn 12y agoThere are dozens of open source programming languages. If one really just wants to create a language with improved concurrency support, he/she can just take one and modify it – this would work a lot better than relying on ready-made components/libraries which can't be modified. There are some mature languages with an active "modding" community. Haskell, for example.
- twic 12y agoSurely what we need, the thing that would make focused innovation easiest, is the ability to implement Go's concurrency model in an existing language? Which we have. Several groups have done this. eg http://docs.paralleluniverse.co/quasar/ http://docs.paralleluniverse.co/quasar/
- firethief 12y agoCommon libraries in C could easily be used via FFI in most languages; they generally aren't because different languages have different paradigms (you might even say that's their purpose), and translations from one language's idioms into another are always lossy. Besides, users of a library in language X don't want to have to read language Y to look under the hood.
- throwaway90999 12y ago"Sad that we still don't have any kind of common libraries or whatever" We do have those. In this case the common library is called "libc." In this case (and in a few others) the Go team decided to intentionally avoid providing an interface to this function. The good news is it would take just a few minutes to add support for go to call strftime directly from libc.
- nemothekid 12y agoThe Go date format is one my huge annoyances about the language (not generics, interface{} magic, or the lack of immutable types). My biggest issue is that despite the fact the designers call Strftime bad because no one remembers the letters, and has to have documentation handy - the Go docs don't even document the magic numbers you have to use. Why 2006? How do I represent a day? When do I use _2 vs 2? Its very poorly documented and thankfully all I use is RFC3339 and Unix timestamps.
- enneff 12y agoIf you ask "Why 2006?" then you missed the point. Mon Jan 2 15:04:05 -0700 MST 2006 0 1 2 3 4 5 6 How to represent a day? "2". Want a leading zero? "02".
- nemothekid 12y agoAgain, where in the documentation is this listed? Why is the timezone 7 even though its before the year? Did you just make this up? It seems to me that this might just be a happy coincidence in the way you ordered the date.
- tedunangst 12y agoIt's in the documentation right where you'd expect it to be. http://golang.org/pkg/time/#pkg-constants http://golang.org/pkg/time/#pkg-constants
- jerf 12y agoHere, directly below the actual listing of the constants: http://golang.org/pkg/time/#pkg-constants http://golang.org/pkg/time/#pkg-constants But I would also observe I missed this documentation myself a couple of times, and I think it probably should have gone on the package documentation, so while I'm linking you to this, I'm not necessarily disagreeing that it's misplaced a bit.
- enneff 12y agoIt's in the documentation for the Format method, which is where I'd expect to find it: http://golang.org/pkg/time/#Time.Format http://golang.org/pkg/time/#Time.Format That it's in order is an intentional mnemonic. I'm not sure why the 7 comes later, but appears earlier.
- deleted 12y ago[deleted]
- lohengramm 12y agoI personally love the way it works. This is actually one of my arguments in favor of the golang standard library which is, in my opinion, a great piece of software by itself.
- RubyPinch 12y agogrey on white, lightgrey on white, yellow on white my oh my, my slightly blurred vision is having fun
- adwf 12y agoI understand there may be legacy issues from other languages, but in a new language... why on earth would you not take the time to make %p the lower case am/pm and %P - AM/PM?
- adsche 12y ago> Because I've used sprintf a million times before Did you mean strftime?
- jrockway 12y agoThat's different too, of course. Everything is %v. Just use %v.
- peterwwillis 12y agoWho the fuck buys a domain name and sets up a web site just because they're frustrated at a date format? I don't get kids today.
- frikk 12y ago$8/year, for fun. Why not? Probably took an hour to do.
- peterwwillis 12y agoI can do a lot of things in an hour. I could yell out my window for an hour. I could rant on irc for an hour. I could write a blog post about how pissed I am for an hour. I could register a domain name, make a website, host and publish it on news sites, then track the comments of people who comment on it, in an hour. I'd rather either patch Go or focus on something positive/productive for an hour. Call me crazy.
- twotwotwo 12y agoFirst: neat, funny ("I can now write Go date format strings...you win this time"), and I follow the "sprintf may be awful but at least I know it" argument. While there's a lot to say for sticking to your language's idioms even when it's a pain, if you really need/want strftime there are third-party libraries: https://github.com/search?l=Go&q=strftime https://github.com/search?l=Go&q=strftime
- squiguy7 12y agoI'm no designer but that yellow color used on the site is not easy to read.
- nothrabannosir 12y agoPeople who say "he could just use sprintf" are missing the point: this lets you use sprintf while writing idiomatic Go. If I see a Go programmer import a sprintf library just because he doesn't want to conform to the programming environment, that's going to ruffle some feathers during code review. But if he uses this, well, I'd be none the wiser. Readability counts.
- DAddYE 12y ago> Readability counts. Oh yeah: `01200602150405`
- nothrabannosir 12y agoLook, I'm not trying to make an argument for how good or bad Go's string formatting is. Tbh I forget both and I find myself back in the documentation either way. But in this case, you're programming Go already. Better stick with the tools that everyone knows and expects. In .go files, Go code is more readable. In .py, it's not. People who read your Go code will know Go, and they will be in "Go mode". To them a Go-style date formatting string will make more sense than a sprintf one.
- Dylan16807 12y agoWhy would you pack it like that with no delimiters? If you want something with only digits then use seconds since epoch.
- enneff 12y agoLooks like `mmyyyyddhhmmss`? (I've never seen month-year-day before, that's threw me for a second.)
- arvinsim 12y agoI just recently had this problem while working with Hugo, a Go static site generator. Suffice to say, it was not intuitive at all. I had to look at the support forums to learn about this Go eccentricity. I can't say that I hate it. I could probably get used to it.
- YesThatTom2 12y agoI generally agree with Cox but "no one remembers all the letters, so the only way to use it is with documentation in hand." Huh? Who can remember the numbers? The only way to use this format is with the documentation. It is an easier to read and verify format. However if you think a casual user will remember that "02" is hour and "03" is... wait, is 02 hour? Let me check the documentation.
- deleted 12y ago[deleted]