

GitHub - soniah/date_practice: exercises for practicing golang date parsing
source link: https://github.com/soniah/date_practice
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Date Practice
Parsing dates is the programmer's equivalent of doing your taxes - you've got to do it, it's fidly and easy to get wrong, and you want it quick and painless.
Previously I'd read package time, got confused
by the reference time layout Mon Jan 2 15:04:05 MST 2006
and fought my
way through various StackOverflow Questions. Or used
imetakeule/fmtdate.
Hence I wrote these exercises for myself, and I now find Golang's date parsing very logical and easy (excepting some corner cases). Hopefully the exercises will be of use to others. I'm interested in more questions - pull requests welcome.
Contributors
Thanks to the following contributors:
- @oylenshpeegul Tim Heaney, who came back with fixes hours after release
Instructions
git clone https://github.com/soniah/date_practice
go test
Edit dates_test.go
until all tests pass.
Many of the dates were printed out using time.Format()
with the provided
common layout strings. You could of course use these layouts to parse the
dates but you wouldn't learn much. Instead write your own layouts.
My answers are in the branch answers
but no peeking!
Where the dates don't have timezones they in are in Hong Kong time.
Hints
-
when parsing difficult dates you can build up the layout chunk-by-chunk - time.Parse() will print out the remaining unmatched text
-
Mon Jan 2 15:04:05 MST 2006
and01/02 03:04:05PM '06 -0700
Useful Links
Recommend
-
48
Is there an emacs game for practicing cursor control? So I was wondering if there's a game out there that lets me practice my emacs cursor skills. I just...
-
86
Don't get pwned: practicing the principle of le...
-
53
grep Command Line | Learn By Practicing (Examples and Exercises)
-
3
Why Do So Many Practicing Data Scientists Not Understand Logistic Regression? The U.S. Weather Service has always phrased rain forecasts as probabilities. I do not want a classification of “it will rain today.” There...
-
10
Introduction I have always wanted to build a software product as a side project. Something that I could gradually improve and work on for years without deadlines and technology restrictions. Something that was my side-projec...
-
13
Lesson 2: Practicing X-Ray and Time-Lapse Vision Calculus trains us to use X-Ray and Time-Lapse vision, such as re-arranging a circle into the “ring triangle” we saw in the previous chapter. This makes finding the area… we...
-
14
Practicing Evolutionary Management at Trainline: Evolutionary Purpose and the Magic of Measuring Team Morale
-
18
Python Practice Problems: Parsing CSV Files ...
-
4
JavaScript is a language that can be intimidating for newcomers. But it’s actually easier than it seems.One of the ways to get started is to do practice exercises. But there are so many online that it can be hard to choose the right on...
-
6
Introduction Structured Query Language (SQL) is a powerful tool for managing and manipulating relational databases. Whether you are a budding data scientist, a web developer, or someone looking to enhance your database...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK