Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ec_date.erl] Redundant parse() clauses #70

Closed
l3kn opened this issue Aug 28, 2014 · 0 comments
Closed

[ec_date.erl] Redundant parse() clauses #70

l3kn opened this issue Aug 28, 2014 · 0 comments

Comments

@l3kn
Copy link

l3kn commented Aug 28, 2014

The parse clauses

parse([Year,X,Month,X,Day,Hour,$:,Min,$:,Sec,$., Ms | PAM], _Now, _Opts)
  when ?is_meridian(PAM) andalso
       (?is_us_sep(X) orelse ?is_world_sep(X))
       andalso ?is_year(Year) ->
    {{Year, Month, Day}, {hour(Hour, PAM), Min, Sec}, {Ms}};

and

parse([Year,X,Month,X,Day,Hour,$:,Min,$:,Sec,$., Ms], _Now, _Opts)
  when  (?is_us_sep(X) orelse ?is_world_sep(X))
        andalso ?is_year(Year) ->
    {{Year, Month, Day}, {hour(Hour,[]), Min, Sec}, {Ms}};

in the file ec_date.erl (lines 155 to 178) seem to be equivalent, since they both match lists without a value for PAM.

6> [Year,X,Month,X,Day,Hour,$:,Min,$:,Sec,$., Ms | PAM] = [2014,$-,8,$-,28,23,$:,39,$:,10,$.,1].   
[2014,45,8,45,28,23,58,39,58,10,46,1]
7> PAM.
[]
8> [Year,X,Month,X,Day,Hour,$:,Min,$:,Sec,$., Ms] = [2014,$-,8,$-,28,23,$:,39,$:,10,$.,1].
[2014,45,8,45,28,23,58,39,58,10,46,1]

In the first case PAM is set to [] which would pass the ?is_meridian(PAM) guard

-define( is_meridian(X), (X==[] orelse X==[am] orelse X==[pm]) ).

and result in hour(Hour, PAM) being equivalent to hour(Hour, []).

This affects the four clauses below (lines 173, 176, 184, 187), too. The only difference is that
in this case the first two clauses use the ?is_year(Year) guard and the latter two ?is_month(Month).

Note: I am not too familiar with Erlang and might be missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant