Unlinks, then symlinks /etc/localtime to the set timezone.

    The timezone is crucial to several system processes, each of which SHOULD
    be restarted (for instance, whatever you system uses as its cron and
    syslog daemons). This will not be automagically done and must be done
    manually!

    CLI Example:

    .. code-block:: bash

        salt '*' timezone.set_zone 'America/Denver'

    .. versionchanged:: 2016.11.4

    .. note::

        On AIX operating systems, Posix values are also allowed, see below

    .. code-block:: bash

        salt '*' timezone.set_zone 'CST6CDT,M3.2.0/2:00:00,M11.1.0/2:00:00'

def set_zone(timezone):
    '''
    Unlinks, then symlinks /etc/localtime to the set timezone.

    The timezone is crucial to several system processes, each of which SHOULD
    be restarted (for instance, whatever you system uses as its cron and
    syslog daemons). This will not be automagically done and must be done
    manually!

    CLI Example:

    .. code-block:: bash

        salt '*' timezone.set_zone 'America/Denver'

    .. versionchanged:: 2016.11.4

    .. note::

        On AIX operating systems, Posix values are also allowed, see below

    .. code-block:: bash

        salt '*' timezone.set_zone 'CST6CDT,M3.2.0/2:00:00,M11.1.0/2:00:00'

    '''
    if salt.utils.path.which('timedatectl'):
        try:
            __salt__['cmd.run']('timedatectl set-timezone {0}'.format(timezone))
        except CommandExecutionError:
            pass

    if 'Solaris' in __grains__['os_family'] or 'AIX' in __grains__['os_family']:
        zonepath = '/usr/share/lib/zoneinfo/{0}'.format(timezone)
    else:
        zonepath = '/usr/share/zoneinfo/{0}'.format(timezone)

    if not os.path.exists(zonepath) and 'AIX' not in __grains__['os_family']:
        return 'Zone does not exist: {0}'.format(zonepath)

    tzfile = _get_localtime_path()
    if os.path.exists(tzfile):
        os.unlink(tzfile)

    if 'Solaris' in __grains__['os_family']:
        __salt__['file.sed'](
            '/etc/default/init', '^TZ=.*', 'TZ={0}'.format(timezone))
    elif 'AIX' in __grains__['os_family']:
        # timezone could be Olson or Posix
        curtzstring = get_zone()
        cmd = ['chtz', timezone]
        result = __salt__['cmd.retcode'](cmd, python_shell=False)
        if result == 0:
            return True

        # restore orig timezone, since AIX chtz failure sets UTC
        cmd = ['chtz', curtzstring]
        __salt__['cmd.retcode'](cmd, python_shell=False)
        return False
    else:
        os.symlink(zonepath, tzfile)

    if 'RedHat' in __grains__['os_family']:
        __salt__['file.sed'](
            '/etc/sysconfig/clock', '^ZONE=.*', 'ZONE="{0}"'.format(timezone))
    elif 'Suse' in __grains__['os_family']:
        __salt__['file.sed'](
            '/etc/sysconfig/clock', '^TIMEZONE=.*', 'TIMEZONE="{0}"'.format(timezone))
    elif 'Debian' in __grains__['os_family'] or 'Gentoo' in __grains__['os_family']:
        with salt.utils.files.fopen('/etc/timezone', 'w') as ofh:
            ofh.write(salt.utils.stringutils.to_str(timezone).strip())
            ofh.write('\n')

    return True