Time-OlsonTZ-Data

 view release on metacpan or  search on metacpan

tzsrc/tzselect.ksh  view on Meta::CPAN


    # Make sure the corresponding zoneinfo file exists.
    TZ_for_date=$TZDIR/$tz
    <"$TZ_for_date" || {
      say >&2 "$0: time zone files are not set up correctly"
      exit 1
    }
  esac


  # Use the proposed TZ to output the current date relative to UTC.
  # Loop until they agree in seconds.
  # Give up after 8 unsuccessful tries.

  extra_info=
  for i in 1 2 3 4 5 6 7 8
  do
    TZdate=$(LANG=C TZ="$TZ_for_date" date)
    UTdate=$(LANG=C TZ=UTC0 date)
    TZsecsetc=${TZdate##*[0-5][0-9]:}
    UTsecsetc=${UTdate##*[0-5][0-9]:}
    if test "${TZsecsetc%%[!0-9]*}" = "${UTsecsetc%%[!0-9]*}"
    then
      extra_info="
Selected time is now:	$TZdate.
Universal Time is now:	$UTdate."
      break
    fi
  done


  # Output TZ info and ask the user to confirm.

  echo >&2 ""
  echo >&2 "Based on the following information:"
  echo >&2 ""
  case $time%$country_result%$region%$coord in
  ?*%?*%?*%)
    say >&2 "	$time$newline	$country_result$newline	$region";;
  ?*%?*%%|?*%%?*%) say >&2 "	$time$newline	$country_result$region";;
  ?*%%%)	say >&2 "	$time";;
  %?*%?*%)	say >&2 "	$country_result$newline	$region";;
  %?*%%)	say >&2 "	$country_result";;
  %%?*%?*)	say >&2 "	coord $coord$newline	$region";;
  %%%?*)	say >&2 "	coord $coord";;
  *)		say >&2 "	TZ='$tz'"
  esac
  say >&2 ""
  say >&2 "TZ='$tz' will be used.$extra_info"
  say >&2 "Is the above information OK?"

  doselect Yes No
  ok=$select_result
  case $ok in
  Yes) break
  esac
do coord=
done

case $SHELL in
*csh) file=.login line="setenv TZ '$tz'";;
*)    file=.profile line="export TZ='$tz'"
esac

test -t 1 && say >&2 "
You can make this change permanent for yourself by appending the line
	$line
to the file '$file' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the $0 command in shell scripts:"

say "$tz"



( run in 0.593 second using v1.01-cache-2.11-cpan-39bf76dae61 )