Skip to content

Commit

Permalink
rename new public function; replace funcerr() by funcerr cmd. or erro…
Browse files Browse the repository at this point in the history
…rif() function;
  • Loading branch information
atecon committed Jan 15, 2022
1 parent d4a8838 commit 224ae2d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
18 changes: 9 additions & 9 deletions src/calendar_utils.gfn
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ date_format: string, Format of 'dates', e.g. "%Y-%m-%d"
Return:
Series holding cast values of 'dates' in the numeric ISO8601 format (YYYYMMDD).

WARNING: Before gretl 2021e, there was a gretl bug in strptime() when the date
WARNING: Up to gretl version 2021d, there was a gretl bug in strptime() when the date
format passed did not consist of a month and day component, respectively. This
bug leads to a wrong date returned. See here:
https://gretlml.univpm.it/hyperkitty/list/gretl-devel@gretlml.univpm.it/message/6ENWKDGSYB32ZFKHENLPFJSS3X22JGYB/
Expand All @@ -64,7 +64,7 @@ format given).


-----------------------------------------------------------------------
Function: iso8601_to_dates_array(const series dates)
Function: iso8601_to_dates(const series dates)

Arguments:
dates: series, Series of numeric ISO8601 dates
Expand Down Expand Up @@ -122,7 +122,7 @@ the help on these functions for more details.
Changelog
---------
- v0.4, January 2022:
+ New iso8601_to_dates_array() function
+ New iso8601_to_dates() function
- v0.3, October 2021:
+ Improved help text
+ New gdate_to_iso8601() function
Expand Down Expand Up @@ -205,7 +205,7 @@ In case of an error, an empty string is returned. */
string date
catch string date = isodate(epochday(value), 1)
if $error
sprintf("Numeric value %d cannot be cast to date string.", value)
sprintf("ERROR: Numeric value %d cannot be cast to date string.", value)
return ""
endif
return date
Expand Down Expand Up @@ -235,7 +235,7 @@ errorif(nelem(parts) != 2, "Invalid date string input. Must be of format '%
return get_iso_date(parts, frequency)
</code>
</gretl-function>
<gretl-function name="iso8601_to_dates_array" type="strings">
<gretl-function name="iso8601_to_dates" type="strings">
<params count="1">
<param name="dates" type="series" const="true">
<description>Num. ISO8601 date</description>
Expand Down Expand Up @@ -269,14 +269,14 @@ if $datatype == 2
elif $datatype == 3
pd = $nobs / $pd
else
funcerr(&quot;Dataset must be either of type time-series or panel.&quot;)
funcerr &quot;Dataset must be either of type time-series or panel.&quot;
endif
if pd == 4
return &quot;quarterly&quot;
elif pd == 12
return &quot;monthly&quot;
else
funcerr(sprintf(&quot;Periodicity of the dataset (pd = %d) is not supported.&quot;, $pd))
errorif(TRUE, sprintf(&quot;Periodicity of the dataset (pd = %d) is not supported.&quot;, $pd))
endif
</code>
</gretl-function>
Expand Down Expand Up @@ -316,7 +316,7 @@ elif frequency == &quot;monthly&quot;
errorif(first &lt; 1000 || first &gt; 9999, &quot;Year out of range&quot;)
errorif(second &lt; 1 || second &gt; 12, &quot;Month out of range&quot;)
else
funcerr(sprintf(&quot;Frequency '%s' not supported.&quot;, frequency))
errorif(TRUE, sprintf(&quot;Frequency '%s' not supported.&quot;, frequency))
endif
</code>
</gretl-function>
Expand Down Expand Up @@ -354,7 +354,7 @@ format (&quot;YYYY-MM-DD&quot;) which can be used to for &quot;stringifying&quot
too. */
nulldata 3
series input = {20220101, NA, 20220103}'
strings dates = iso8601_to_dates_array(input)
strings dates = iso8601_to_dates(input)
series x = dates # Cast as series

print dates
Expand Down
10 changes: 5 additions & 5 deletions src/calendar_utils.inp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ function string numeric_to_extended_iso8601 (const int value "ISO8601 numeric da

catch string date = isodate(epochday(value), 1)
if $error
sprintf("Numeric value %d cannot be cast to date string.", value)
sprintf("ERROR: Numeric value %d cannot be cast to date string.", value)
return ""
endif

return date
end function


function strings iso8601_to_dates_array (const series dates "Num. ISO8601 date")
function strings iso8601_to_dates (const series dates "Num. ISO8601 date")
/* Based on a series in numeric iso8601 format, an array of strings in the extended ISO8601 format ("YYYY-MM-DD") is returned. */

strings ret = array($nobs)
Expand Down Expand Up @@ -107,15 +107,15 @@ function string get_frequency_label (void)
elif $datatype == 3
pd = $nobs / $pd
else
funcerr("Dataset must be either of type time-series or panel.")
funcerr "Dataset must be either of type time-series or panel."
endif

if pd == 4
return "quarterly"
elif pd == 12
return "monthly"
else
funcerr(sprintf("Periodicity of the dataset (pd = %d) is not supported.", $pd))
errorif(TRUE, sprintf("Periodicity of the dataset (pd = %d) is not supported.", $pd))
endif
end function

Expand Down Expand Up @@ -179,6 +179,6 @@ function void check_frequency_ranges (const int first,
errorif(first < 1000 || first > 9999, "Year out of range")
errorif(second < 1 || second > 12, "Month out of range")
else
funcerr(sprintf("Frequency '%s' not supported.", frequency))
errorif(TRUE, sprintf("Frequency '%s' not supported.", frequency))
endif
end function
2 changes: 1 addition & 1 deletion src/calendar_utils.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ date = 2022-01-14
description = Collection of useful date time related tools
tags = C88
min-version = 2020c
public = create_iso8601_series dates_to_iso8601 date_to_iso8601 numeric_to_extended_iso8601 gdate_to_iso8601 iso8601_to_dates_array
public = create_iso8601_series dates_to_iso8601 date_to_iso8601 numeric_to_extended_iso8601 gdate_to_iso8601 iso8601_to_dates
data-requirement = no-data-ok
help = calendar_utils_help.txt
sample-script = calendar_utils_sample.inp
6 changes: 3 additions & 3 deletions src/calendar_utils_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ date_format: string, Format of 'dates', e.g. "%Y-%m-%d"
Return:
Series holding cast values of 'dates' in the numeric ISO8601 format (YYYYMMDD).

WARNING: Before gretl 2021e, there was a gretl bug in strptime() when the date
WARNING: Up to gretl version 2021d, there was a gretl bug in strptime() when the date
format passed did not consist of a month and day component, respectively. This
bug leads to a wrong date returned. See here:
https://gretlml.univpm.it/hyperkitty/list/gretl-devel@gretlml.univpm.it/message/6ENWKDGSYB32ZFKHENLPFJSS3X22JGYB/
Expand All @@ -55,7 +55,7 @@ format given).


-----------------------------------------------------------------------
Function: iso8601_to_dates_array(const series dates)
Function: iso8601_to_dates(const series dates)

Arguments:
dates: series, Series of numeric ISO8601 dates
Expand Down Expand Up @@ -113,7 +113,7 @@ the help on these functions for more details.
Changelog
---------
- v0.4, January 2022:
+ New iso8601_to_dates_array() function
+ New iso8601_to_dates() function
- v0.3, October 2021:
+ Improved help text
+ New gdate_to_iso8601() function
Expand Down
2 changes: 1 addition & 1 deletion src/calendar_utils_sample.inp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ format ("YYYY-MM-DD") which can be used to for "stringifying" a series,
too. */
nulldata 3
series input = {20220101, NA, 20220103}'
strings dates = iso8601_to_dates_array(input)
strings dates = iso8601_to_dates(input)
series x = dates # Cast as series

print dates
Expand Down
8 changes: 4 additions & 4 deletions tests/run_tests.inp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ test_numeric_to_ext_iso8601()


nulldata 3 --preserve
function void test_iso8601_to_dates_array (void)
print "Start with iso8601_to_dates_array()."
function void test_iso8601_to_dates (void)
print "Start with iso8601_to_dates()."

# Given
series input = {20220101, NA, 20220103}'
Expand All @@ -157,14 +157,14 @@ function void test_iso8601_to_dates_array (void)
"2022-01-03")

# When
strings actual = iso8601_to_dates_array(input)
strings actual = iso8601_to_dates(input)

# Then
loop i=1..nelem(expected)
assert(actual[i] == expected[i])
endloop
end function
test_iso8601_to_dates_array()
test_iso8601_to_dates()


bundles Params = null
Expand Down

0 comments on commit 224ae2d

Please sign in to comment.