コード例 #1
0
    # resources...

    conf = TimezoneConf.load(Host)

    # ----------------------------------------------------------------------------------------------------------------
    # run...

    now = LocalizedDatetime.now()

    if cmd.list:
        for zone in Timezone.zones():
            print(zone, file=sys.stderr)
        exit(0)

    elif cmd.set():
        if not Timezone.is_valid(cmd.zone):
            print("zone is not valid: %s" % cmd.zone, file=sys.stderr)
            exit(1)

        if cmd.zone != conf.name:
            conf = TimezoneConf(now, cmd.zone)
            conf.save(Host)

    elif cmd.link:
        if not conf.uses_system_name() or conf.set_on is None:
            conf = TimezoneConf(now, None)
            conf.save(Host)

    print(JSONify.dumps(conf))

    if cmd.verbose:
コード例 #2
0
ファイル: timezone_test.py プロジェクト: motius/scs_core
from scs_core.data.localized_datetime import LocalizedDatetime
from scs_core.data.json import JSONify

from scs_core.location.timezone import Timezone
from scs_core.location.timezone_conf import TimezoneConf

# --------------------------------------------------------------------------------------------------------------------

for zone_name in Timezone.zones():
    print(zone_name)

print("=")

zone_name = "Europe/London"  # Etc/UTC  US/Michigan  Europe/London   Asia/Calcutta
print("zone_name: %s" % zone_name)
print("valid: %s" % Timezone.is_valid(zone_name))

print("-")

now = LocalizedDatetime.now()

zone_conf = TimezoneConf(now, zone_name)
print(zone_conf)
print(JSONify.dumps(zone_conf))

print("-")

zone = zone_conf.timezone()
print(zone)
print(JSONify.dumps(zone))