Skip to content

Commit 339cfa1

Browse files
Merge pull request #225 from RonnyPfannschmidt/timestamp-formating
internal refactoring to support specifying datetime formats more easyly
2 parents 366e658 + b4be6ea commit 339cfa1

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

setuptools_scm/version.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ def __repr__(self):
8686
'<ScmVersion {tag} d={distance}'
8787
' n={node} d={dirty} x={extra}>')
8888

89-
def format_with(self, fmt):
89+
def format_with(self, fmt, **kw):
9090
return fmt.format(
9191
time=self.time,
9292
tag=self.tag, distance=self.distance,
93-
node=self.node, dirty=self.dirty, extra=self.extra)
93+
node=self.node, dirty=self.dirty, extra=self.extra, **kw)
9494

95-
def format_choice(self, clean_format, dirty_format):
96-
return self.format_with(dirty_format if self.dirty else clean_format)
95+
def format_choice(self, clean_format, dirty_format, **kw):
96+
return self.format_with(
97+
dirty_format if self.dirty else clean_format, **kw)
9798

9899

99100
def _parse_tag(tag, preformatted):
@@ -144,25 +145,24 @@ def guess_next_dev_version(version):
144145
return guess_next_version(version.tag, version.distance)
145146

146147

147-
def get_local_node_and_date(version):
148+
def _format_local_with_time(version, time_format):
149+
148150
if version.exact or version.node is None:
149-
return version.format_choice("", "+d{time:%Y%m%d}")
151+
return version.format_choice(
152+
"", "+d{time:{time_format}}",
153+
time_format=time_format)
150154
else:
151-
return version.format_choice("+{node}", "+{node}.d{time:%Y%m%d}")
155+
return version.format_choice(
156+
"+{node}", "+{node}.d{time:{time_format}}",
157+
time_format=time_format)
158+
159+
160+
def get_local_node_and_date(version):
161+
return _format_local_with_time(version, time_format="%Y%m%d")
152162

153163

154164
def get_local_node_and_timestamp(version, fmt='%Y%m%d%H%M%S'):
155-
if version.exact or version.node is None:
156-
return version.format_choice("",
157-
"+d{time:"
158-
+ "{fmt}".format(fmt=fmt)
159-
+ "}")
160-
else:
161-
return version.format_choice("+{node}",
162-
"+{node}"
163-
+ ".d{time:"
164-
+ "{fmt}".format(fmt=fmt)
165-
+ "}")
165+
return _format_local_with_time(version, time_format=fmt)
166166

167167

168168
def get_local_dirty_tag(version):

0 commit comments

Comments
 (0)