Skip to content

Commit 3aaf44a

Browse files
committed
Improve Figure.timestamp
1 parent 8d7fb60 commit 3aaf44a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

pygmt/src/timestamp.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
__doctest_skip__ = ["timestamp"]
1515

1616

17-
# ruff: noqa: ARG001
1817
def timestamp(
1918
self,
2019
text: str | None = None,
@@ -79,6 +78,14 @@ def timestamp(
7978
"""
8079
self._preprocess()
8180

81+
if text is not None and len(text) > 64:
82+
msg = (
83+
"Argument of 'text' must be no longer than 64 characters. "
84+
"The given text string will be truncated to 64 characters."
85+
)
86+
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2)
87+
text = text[:64]
88+
8289
# TODO(GMT>=6.5.0): Remove the patch for upstream bug fixed in GMT 6.5.0.
8390
if Version(__gmt_version__) < Version("6.5.0"):
8491
# Giving a single offset doesn't work.
@@ -89,16 +96,7 @@ def timestamp(
8996
# See https://github.com/GenericMappingTools/gmt/pull/7127.
9097
if text is not None:
9198
# Overriding the 'timefmt' parameter and set 'text' to None
92-
timefmt = text[:64]
93-
text = None
94-
95-
if text is not None and len(text) > 64:
96-
msg = (
97-
"Argument of 'text' must be no longer than 64 characters. "
98-
"The given text string will be truncated to 64 characters."
99-
)
100-
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2)
101-
text = text[:64]
99+
timefmt, text = text, None
102100

103101
kwdict = AliasSystem(
104102
U=[

0 commit comments

Comments
 (0)