[ec_date.erl] Redundant parse() clauses
The parse clauses
``` erlang
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
``` erlang
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](https://github.com/erlware/erlware_commons/blob/master/src/ec_date.erl#L155) (lines 155 to 178) seem to be equivalent, since they both match lists without a value for `PAM`.
``` erlang
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
``` erlang
-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._
关闭于 2023-12-12 0 条评论