Skip to content

Commit

Permalink
refactor lat/long hebcal command args to avoid duplication of code
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael J. Radwin authored and Michael J. Radwin committed Jun 23, 2015
1 parent ccb4d63 commit bbf8a69
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
5 changes: 2 additions & 3 deletions hebcal.com/bin/create_shabbat_browse.pl
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ sub write_candle_lighting {

sub get_candle_lighting {
my($latitude,$longitude,$tzid,$country,$asciiname,$admin1) = @_;
my($lat_deg,$lat_min,$long_deg,$long_min) =
Hebcal::latlong_to_hebcal($latitude, $longitude);
my $cmd = $Hebcal::HEBCAL_BIN . " -L $long_deg,$long_min -l $lat_deg,$lat_min -z '$tzid'";
my $cmd = $Hebcal::HEBCAL_BIN;
$cmd .= Hebcal::cmd_latlong($latitude,$longitude,$tzid);
if ($country eq "IL") {
$cmd .= " -i";
$cmd .= " -b 40" if index($admin1, "Jerusalem") == 0;
Expand Down
11 changes: 3 additions & 8 deletions local/bin/shabbat_weekly.pl
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,9 @@ sub parse_config {
WARN("Unknown tzid for to=$to, id=$cfg->{id}")
unless defined $tzid;

my $cmd = "$HOME/web/hebcal.com/bin/hebcal";
if ($is_jerusalem) {
$cmd .= " -C 'Jerusalem'";
} else {
my($lat_deg,$lat_min,$long_deg,$long_min) =
Hebcal::latlong_to_hebcal($latitude, $longitude);
$cmd .= " -L $long_deg,$long_min -l $lat_deg,$lat_min -z '$tzid'";
}
my $cmd = $Hebcal::HEBCAL_BIN;
$cmd .= Hebcal::cmd_latlong($latitude,$longitude,$tzid);
$cmd .= " -b 40" if $is_jerusalem;

$cmd .= " -i" if $is_israel;

Expand Down
37 changes: 20 additions & 17 deletions local/share/perl/site_perl/Hebcal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1316,10 +1316,7 @@ sub zipcode_get_zip_fields($$)
}

my $tzid = get_usa_tzid($State,$TimeZone,$DayLightSaving);
my($lat_deg,$lat_min,$long_deg,$long_min) =
latlong_to_hebcal($Latitude, $Longitude);
($CityMixedCase,$State,$tzid,
$Latitude,$Longitude,$lat_deg,$lat_min,$long_deg,$long_min);
($CityMixedCase,$State,$tzid,$Latitude,$Longitude);
}

sub woe_city_descr {
Expand Down Expand Up @@ -1617,7 +1614,7 @@ sub process_args_common_zip {
}

my $DB = zipcode_open_db();
my($city,$state,$tzid,$latitude,$longitude,$lat_deg,$lat_min,$long_deg,$long_min) =
my($city,$state,$tzid,$latitude,$longitude) =
zipcode_get_zip_fields($DB, $q->param("zip"));
zipcode_close_db($DB);
undef($DB);
Expand All @@ -1629,7 +1626,9 @@ sub process_args_common_zip {
return (0,$message,$help);
}

my $cmd = "./hebcal -L $long_deg,$long_min -l $lat_deg,$lat_min -z '$tzid'";
my $cmd = "./hebcal";
$cmd .= cmd_latlong($latitude,$longitude,$tzid);

my $city_descr = "$city, $state " . $q->param('zip');

$q->param("geo", "zip");
Expand Down Expand Up @@ -1691,9 +1690,8 @@ sub process_args_common_geoname {
return (0, $message, $help);
}

my($lat_deg,$lat_min,$long_deg,$long_min) =
latlong_to_hebcal($latitude, $longitude);
my $cmd = "./hebcal -L $long_deg,$long_min -l $lat_deg,$lat_min -z '$tzid'";
my $cmd = "./hebcal";
$cmd .= cmd_latlong($latitude,$longitude,$tzid);
my $city_descr = geoname_city_descr($name,$admin1,$country);
if ($country eq "Israel") {
$q->param('i','on');
Expand Down Expand Up @@ -1736,6 +1734,15 @@ sub legacy_tz_dst_to_tzid {
return undef;
}

sub cmd_latlong {
my($latitude,$longitude,$tzid) = @_;

my($lat_deg,$lat_min,$long_deg,$long_min) =
latlong_to_hebcal($latitude, $longitude);

return " -L $long_deg,$long_min -l $lat_deg,$lat_min -z '$tzid'";
}

sub process_args_common_geopos2 {
my($q,$cconfig) = @_;

Expand Down Expand Up @@ -1764,10 +1771,8 @@ sub process_args_common_geopos2 {

my $city_descr = "$latitude, $longitude, $tzid";

my($lat_deg,$lat_min,$long_deg,$long_min) =
latlong_to_hebcal($latitude, $longitude);

my $cmd = "./hebcal -L $long_deg,$long_min -l $lat_deg,$lat_min -z '$tzid'";
my $cmd = "./hebcal";
$cmd .= cmd_latlong($latitude,$longitude,$tzid);

if (defined $cconfig) {
$cconfig->{"latitude"} = $latitude;
Expand Down Expand Up @@ -1898,10 +1903,8 @@ sub process_args_common_city {
$q->delete($_);
}

my($lat_deg,$lat_min,$long_deg,$long_min) =
latlong_to_hebcal($latitude, $longitude);

my $cmd = "./hebcal -L $long_deg,$long_min -l $lat_deg,$lat_min -z '$tzid'";
my $cmd = "./hebcal";
$cmd .= cmd_latlong($latitude,$longitude,$tzid);

my $city_descr = geoname_city_descr($name,$admin1,$country);
if ($country eq "Israel") {
Expand Down

0 comments on commit bbf8a69

Please sign in to comment.