Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
MichelJuillard
Periods.jl
Commits
a9273d13
Commit
a9273d13
authored
Mar 09, 2020
by
Michel Juillard
Browse files
Improve SimplePeriod
parent
b5abcea7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Project.toml
View file @
a9273d13
...
...
@@ -2,3 +2,6 @@ name = "Periods"
uuid
=
"0c1d1a06-9168-427d-90e3-b4d73349562f"
authors
=
[
"michel "
]
version
=
"0.1.0"
[deps]
Dates
=
"ade2ca70-3891-5945-98fb-dc099432e06a"
src/Periods.jl
View file @
a9273d13
module
Periods
using
Dates
abstract type
AbstractPeriod
end
include
(
"SimplePeriods.jl"
)
...
...
src/SimplePeriods.jl
View file @
a9273d13
...
...
@@ -5,19 +5,44 @@ struct Period <: AbstractPeriod
frequency
::
Frequency
end
function
Period
(
year
,
subperiod
,
f
requency
)
function
Period
(
arg1
::
Integer
,
frequency
::
F
requency
)
if
frequency
==
Year
ordinal
=
year
-
1970
ordinal
=
arg1
-
19070
elseif
frequency
==
Undated
ordinal
-
arg1
else
error
(
"Frequency
$
frequency needs more than one argument"
)
end
Period
(
ordinal
,
frequency
)
end
function
Period
(
arg1
::
Integer
,
arg2
::
Integer
,
frequency
::
Frequency
)
if
frequency
==
Year
ordinal
=
arg1
-
1970
elseif
frequency
==
Semester
@assert
(
subperiod
in
1
:
2
)
ordinal
=
2
*
(
ye
ar
-
1970
)
+
subperiod
-
1
@assert
(
arg2
in
1
:
2
)
ordinal
=
2
*
(
ar
g1
-
1970
)
+
arg2
-
1
elseif
frequency
==
Quarter
@assert
(
subperiod
in
1
:
4
)
ordinal
=
4
*
(
ye
ar
-
1970
)
+
subperiod
-
1
@assert
(
arg2
in
1
:
4
)
ordinal
=
4
*
(
ar
g1
-
1970
)
+
arg2
-
1
elseif
frequency
==
Month
@assert
(
subperiod
in
1
:
12
)
ordinal
=
12
*
(
ye
ar
-
1970
)
+
subperiod
-
1
ordinal
=
12
*
(
ar
g1
-
1970
)
+
arg2
-
1
elseif
frequency
==
Week
ordinal
=
week1970
(
year
,
week
)
ordinal
=
week1970
(
arg1
,
arg2
)
elseif
frequency
==
Undated
ordinal
=
arg1
end
Period
(
ordinal
,
frequency
)
end
function
Period
(
arg1
,
arg2
,
arg3
,
frequency
)
if
frequency
==
Day
return
Period
(
arg1
,
arg2
,
arg3
)
else
return
Period
(
arg1
,
arg2
,
frequency
)
end
end
Period
(
year
::
Integer
,
month
::
Integer
,
day
::
Integer
)
=
(
Date
(
year
,
month
,
day
)
.
value
,
Day
)
Period
(
d
::
Date
)
=
(
d
.
value
,
Day
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment