Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mkexp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esmenv
mkexp
Commits
e8bd4f55
Commit
e8bd4f55
authored
9 years ago
by
Karl-Hermann Wieners
Browse files
Options
Downloads
Patches
Plain Diff
Amended handling of dates
* Added function add_days to handle day offsets for namelist settings
parent
2f1b6247
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
expconfig.py
+45
-3
45 additions, 3 deletions
expconfig.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
test.py
+39
-1
39 additions, 1 deletion
test.py
with
85 additions
and
5 deletions
expconfig.py
+
45
−
3
View file @
e8bd4f55
...
...
@@ -152,7 +152,47 @@ class ExpConfig(ConfigObj):
'''
Add specified number of years (possible negative) to date
'''
years
=
int
(
years
)
dt
=
map
(
int
,
split_date
(
value
))
return
"
{0:04}-{1:02}-{2:02}
"
.
format
(
dt
[
0
]
+
years
,
dt
[
1
],
dt
[
2
])
dt
[
0
]
+=
years
return
"
{:+05}-{:02}-{:02}
"
.
format
(
*
dt
).
lstrip
(
'
+
'
)
def
add_days
(
value
,
days
):
'''
Add specified number of days (possible negative) to date
'''
def
leap
(
year
):
return
(
not
year
%
4
)
and
(
not
(
not
year
%
100
)
or
(
not
year
%
400
))
def
monlen
(
year
,
mon
):
monlens
=
(
0
,
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
,
0
)
return
monlens
[
mon
]
+
(
mon
==
2
and
leap
(
year
))
def
add_days_
(
year
,
mon
,
day
,
days
):
while
True
:
if
mon
==
0
:
year
-=
1
mon
=
12
day
=
monlen
(
year
,
12
)
continue
if
mon
==
13
:
year
+=
1
mon
=
1
day
=
1
continue
if
day
+
days
<=
0
:
days
+=
day
mon
-=
1
day
=
monlen
(
year
,
mon
)
continue
if
day
+
days
>
monlen
(
year
,
mon
):
days
-=
monlen
(
year
,
mon
)
-
day
+
1
mon
+=
1
day
=
1
continue
day
+=
days
break
return
(
year
,
mon
,
day
)
days
=
int
(
days
)
dt
=
map
(
int
,
split_date
(
value
))
dt
=
add_days_
(
dt
[
0
],
dt
[
1
],
dt
[
2
],
days
)
return
"
{:+05}-{:02}-{:02}
"
.
format
(
*
dt
).
lstrip
(
'
+
'
)
def
eval_value
(
value
):
'''
...
...
@@ -189,9 +229,11 @@ class ExpConfig(ConfigObj):
if
match
:
return
eval_value_string
(
match
.
group
(
1
))
match
=
re
.
match
(
r
'
^add_years\(\s*([-\d]+([T ][\d:]+)?)\s*,\s*([-+]?\d+)\s*\)$
'
,
value
,
re
.
S
)
match
=
re
.
match
(
r
'
^add_
(
years
|days)
\(\s*([-\d]+([T ][\d:]+)?)\s*,\s*([-+]?\d+)\s*\)$
'
,
value
,
re
.
S
)
if
match
:
return
add_years
(
match
.
group
(
1
),
match
.
group
(
3
))
if
match
.
group
(
1
)
==
'
days
'
:
return
add_days
(
match
.
group
(
2
),
match
.
group
(
4
))
return
add_years
(
match
.
group
(
2
),
match
.
group
(
4
))
match
=
re
.
match
(
r
'
^split_date\((.*)\)$
'
,
value
,
re
.
S
)
if
match
:
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
e8bd4f55
from
distutils.core
import
setup
name
=
'
mkexp
'
version
=
'
0.3.
0
'
version
=
'
0.3.
1dev
'
setup
(
name
=
name
,
...
...
This diff is collapsed.
Click to expand it.
test.py
+
39
−
1
View file @
e8bd4f55
...
...
@@ -281,7 +281,7 @@ class ContentTestCase(MkexpTestCase):
expected
=
align
(
"""
1235-05-06
1233-05-06
-766-05-06
-
0
766-05-06
11234-05-06
"""
)
ignore
=
output
(
script
(
"
mkexp
"
+
exp_id
+
"
.config
"
))
...
...
@@ -289,5 +289,43 @@ class ContentTestCase(MkexpTestCase):
result
=
align
(
result
)
self
.
assertMultiLineEqual
(
expected
,
result
)
def
test_add_days
(
self
):
exp_id
=
'
test_add_days
'
job_id
=
'
job
'
writeconfig
(
exp_id
,
"""
EXP_TYPE =
DATE = 1234-05-06
NEXT_DATE =
'
add_days($DATE, 1)
'
PREVIOUS_DATE =
'
add_days($DATE, -1)
'
NEGATIVE_DATE =
'
add_days($DATE, -2000)
'
LONGYEAR_DATE =
'
add_days($DATE, 10000)
'
LATE_DATE = 9999-12-31
LATER_DATE =
'
add_days($LATE_DATE, 1)
'
EARLY_DATE = 0000-01-01
EARLIER_DATE =
'
add_days($EARLY_DATE, -1)
'
[jobs]
[[
"""
+
job_id
+
"""
]]
"""
)
writetemplate
(
exp_id
,
job_id
,
"""
%{NEXT_DATE}
%{PREVIOUS_DATE}
%{NEGATIVE_DATE}
%{LONGYEAR_DATE}
%{LATER_DATE}
%{EARLIER_DATE}
"""
)
expected
=
align
(
"""
1234-05-07
1234-05-05
1228-11-13
1261-09-21
10000-01-01
-0001-12-31
"""
)
ignore
=
output
(
script
(
"
mkexp
"
+
exp_id
+
"
.config
"
))
result
=
readfile
(
join
(
"
test
"
,
"
experiments
"
,
exp_id
,
exp_id
+
"
.
"
+
job_id
))
result
=
align
(
result
)
self
.
assertMultiLineEqual
(
expected
,
result
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment