arrow-py / arrow

🏹 Better dates & times for Python
https://arrow.readthedocs.io
Apache License 2.0
8.71k stars 673 forks source link

Create built-in format strings for common formats #791

Closed systemcatch closed 4 years ago

systemcatch commented 4 years ago

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

replaces #770 ref #762

systemcatch commented 4 years ago

@jadchaar @krisfremen let me know what you guys think.

(arrow) chris@ThinkPad:~/arrow$ python
Python 3.7.4 (default, Sep 19 2019, 11:01:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> dt=arrow.utcnow()
>>> dt.format(arrow.FORMAT_
arrow.FORMAT_COOKIE   arrow.FORMAT_RFC1123  arrow.FORMAT_RFC822   arrow.FORMAT_RSS      
arrow.FORMAT_RFC1036  arrow.FORMAT_RFC2822  arrow.FORMAT_RFC850   
>>> dt.format(arrow.FORMAT_COOKIE)
'Tuesday, 19-May-2020 20:19:14 UTC'
>>> dt.format(arrow.FORMAT_RFC822)
'Tue, 19 May 20 20:19:14 +0000'
>>> dt.format(arrow.FORMAT_RFC850)
'Tuesday, 19-May-20 20:19:14 UTC'
>>> dt.format(arrow.FORMAT_RFC1036)
'Tue, 19 May 20 20:19:14 +0000'
>>> dt.format(arrow.FORMAT_RFC1123)
'Tue, 19 May 2020 20:19:14 +0000'
>>> dt.format(arrow.FORMAT_RFC2822)
'Tue, 19 May 2020 20:19:14 +0000'
>>> dt.format(arrow.FORMAT_RSS)
'Tue, 19 May 2020 20:19:14 +0000'
codecov-commenter commented 4 years ago

Codecov Report

Merging #791 into master will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #791   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         1695      1735   +40     
  Branches       289       295    +6     
=========================================
+ Hits          1695      1735   +40     
Impacted Files Coverage Δ
arrow/__init__.py 100.00% <100.00%> (ø)
arrow/formatter.py 100.00% <100.00%> (ø)
arrow/parser.py 100.00% <100.00%> (ø)
arrow/locales.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6fd78a1...a695c69. Read the comment docs.

systemcatch commented 4 years ago

Great I'll work on that.

systemcatch commented 4 years ago

Hey @jadchaar I've added some details to the documentation, let me know what you think.

builtin_formats

systemcatch commented 4 years ago

@jadchaar I added all of the remaining formats.

jadchaar commented 4 years ago

@jadchaar I added all of the remaining formats.

Looks good to me. Do you think we should add a basic, common formats like FORMAT_ISO8601 even if it is a duplicate?

Also, just a thought: should we allow users to pass in a custom separator as an optional argument?

Thirdly, I think we should add a comprehensive list of all the available formats in the docs. They do not all have to be examples in Python prompts, but I think we need a bulleted list of formats that are available.

systemcatch commented 4 years ago

Looks good to me. Do you think we should add a basic, common formats like FORMAT_ISO8601 even if it is a duplicate?

I think we've covered all the bases since ISO 8601 is the default format in format().

Also, just a thought: should we allow users to pass in a custom separator as an optional argument?

Let's keep it simple for now, if there's demand for that we can add it in later.

Thirdly, I think we should add a comprehensive list of all the available formats in the docs. They do not all have to be examples in Python prompts, but I think we need a bulleted list of formats that are available.

Sure but doesn't my code example cover all of them? Where should we put the full list?

systemcatch commented 4 years ago

Great let's decide what we want to do with constants.py then we can merge this in.

systemcatch commented 4 years ago

@jadchaar successfully reverted the constants.py deletion using https://stackoverflow.com/a/953573