Class: Yast::TimezoneClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/Timezone.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) CallMkinitrd



444
445
446
447
448
449
450
451
452
# File '../../src/modules/Timezone.rb', line 444

def CallMkinitrd
  Builtins.y2milestone("calling mkinitrd...")
  SCR.Execute(
    path(".target.bash"),
    "/sbin/mkinitrd >> /var/log/YaST2/y2logmkinitrd 2>> /var/log/YaST2/y2logmkinitrd"
  )
  Builtins.y2milestone("... done")
  true
end

- (Object) CheckDate(day, month, year)



867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
# File '../../src/modules/Timezone.rb', line 867

def CheckDate(day, month, year)
  mdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  ret = true
  yea = Builtins.tointeger(String.CutZeros(year))
  mon = Builtins.tointeger(String.CutZeros(month))
  da = Builtins.tointeger(String.CutZeros(day))
  return false if yea == nil || mon == nil || da == nil
  ret = ret && Ops.greater_or_equal(mon, 1) && Ops.less_or_equal(mon, 12)
  if Ops.modulo(yea, 4) == 0 &&
      (Ops.modulo(yea, 100) != 0 || Ops.modulo(yea, 400) == 0)
    Ops.set(mdays, 1, 29)
  end
  ret = ret && Ops.greater_or_equal(da, 1) &&
    Ops.less_or_equal(da, Ops.get_integer(mdays, Ops.subtract(mon, 1), 0))
  ret = ret && Ops.greater_or_equal(yea, 1970) && Ops.less_than(yea, 2032)
  ret
end

- (Object) CheckTime(hour, minute, second)



853
854
855
856
857
858
859
860
861
862
863
864
865
# File '../../src/modules/Timezone.rb', line 853

def CheckTime(hour, minute, second)
  ret = true
  tmp = Builtins.tointeger(String.CutZeros(hour))
  return false if tmp == nil
  ret = ret && Ops.greater_or_equal(tmp, 0) && Ops.less_than(tmp, 24)
  tmp = Builtins.tointeger(String.CutZeros(minute))
  return false if tmp == nil
  ret = ret && Ops.greater_or_equal(tmp, 0) && Ops.less_than(tmp, 60)
  tmp = Builtins.tointeger(String.CutZeros(second))
  return false if tmp == nil
  ret = ret && Ops.greater_or_equal(tmp, 0) && Ops.less_than(tmp, 60)
  ret
end

- (Hash) Export

AutoYaST interface function: Return the Timezone configuration as a map.

Returns:

  • (Hash)

    with the settings



953
954
955
956
957
958
959
# File '../../src/modules/Timezone.rb', line 953

def Export
  ret = {
    "timezone" => @timezone,
    "hwclock"  => @hwclock == "-u" ? "UTC" : "localtime"
  }
  deep_copy(ret)
end

- (Object) get_lang2tz

get_lang2tz()

Get the language –> timezone conversion map.

Returns:

  • conversion map

See Also:

  • #get_zonemap()


186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File '../../src/modules/Timezone.rb', line 186

def get_lang2tz
  if Builtins.size(@lang2tz) == 0
    base_lang2tz = Convert.to_map(
      SCR.Read(path(".target.yast2"), "lang2tz.ycp")
    )
    base_lang2tz = {} if base_lang2tz == nil

    @lang2tz = Convert.convert(
      Builtins.union(base_lang2tz, Language.GetLang2TimezoneMap(true)),
      :from => "map",
      :to   => "map <string, string>"
    )
  end
  deep_copy(@lang2tz)
end

- (Object) get_zonemap

get_zonemap()

Get the timezone database.

Returns:

  • timezone DB (map)

See Also:

  • #get_lang2tz()


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File '../../src/modules/Timezone.rb', line 210

def get_zonemap
  if Builtins.size(@zonemap) == 0
    zmap = Convert.convert(
      Builtins.eval(SCR.Read(path(".target.yast2"), "timezone_raw.ycp")),
      :from => "any",
      :to   => "list <map <string, any>>"
    )
    zmap = [] if zmap == nil

    @zonemap = Builtins.sort(zmap) do |a, b|
      # [ "USA", "Canada" ] -> [ "Canada", "USA" ]
      # bnc#385172: must use < instead of <=, the following means:
      # strcoll(x) <= strcoll(y) && strcoll(x) != strcoll(y)
      lsorted = Builtins.lsort(
        [Ops.get_string(a, "name", ""), Ops.get_string(b, "name", "")]
      )
      lsorted_r = Builtins.lsort(
        [Ops.get_string(b, "name", ""), Ops.get_string(a, "name", "")]
      )
      Ops.get_string(lsorted, 0, "") == Ops.get_string(a, "name", "") &&
        lsorted == lsorted_r
    end
  end
  deep_copy(@zonemap)
end

- (Object) GetCountryForTimezone(tz)

Return the country part of language code for given timezone

Parameters:

  • timezone,

    if empty the current one is used



559
560
561
# File '../../src/modules/Timezone.rb', line 559

def GetCountryForTimezone(tz)
  Language.GetGivenLanguageCountry(GetLanguageForTimezone(tz))
end

- (Object) GetDateTime(real_time, locale_format)

GetDateTime()

Get the output of date “+%H:%M:%S - %Y-%m-%d” or in locale defined format

Parameters:

  • flag

    if to get real system time or if to simulate changed timezone settings with TZ=

  • if

    the date and time should be returned in locale defined format

Returns:

  • The string output.



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File '../../src/modules/Timezone.rb', line 591

def GetDateTime(real_time, locale_format)
  cmd = ""

  date_format = locale_format && Mode.normal ?
    "+%c" :
    "+%Y-%m-%d - %H:%M:%S"

  Builtins.y2milestone(
    "GetDateTime hwclock %1 real:%2",
    @hwclock,
    real_time
  )
  if !real_time && !Mode.config
    ds = 0
    if @diff != 0
      out2 = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), "date +%z")
      )
      tzd = Ops.get_string(out2, "stdout", "")
      Builtins.y2milestone("GetDateTime tcd=%1", tzd)
      t = Builtins.tointeger(String.CutZeros(Builtins.substring(tzd, 1, 2)))
      if t != nil
        ds = Ops.add(ds, Ops.multiply(t, 3600))
        t = Builtins.tointeger(
          String.CutZeros(Builtins.substring(tzd, 3, 2))
        )
        ds = Ops.add(ds, Ops.multiply(t, 60))
        ds = Ops.unary_minus(ds) if Builtins.substring(tzd, 0, 1) == "-"
        Builtins.y2milestone("GetDateTime ds %1 diff %2", ds, @diff)
      end
    end
    cmd = ""
    cmd = Builtins.sformat("TZ=%1 ", @timezone) if @hwclock != "--localtime"
    cmd = Ops.add(
      cmd,
      Builtins.sformat(
        "/bin/date \"%1\" \"--date=now %2sec\"",
        date_format,
        Ops.multiply(ds, @diff)
      )
    )
  else
    cmd = Builtins.sformat("/bin/date \"%1\"", date_format)
  end
  Builtins.y2milestone("GetDateTime cmd=%1", cmd)
  out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
  local_date = Builtins.deletechars(Ops.get_string(out, "stdout", ""), "\n")

  Builtins.y2milestone("GetDateTime local_date='%1'", local_date)

  local_date
end

- (Object) GetDateTimeMap

Return current date and time in the map



836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
# File '../../src/modules/Timezone.rb', line 836

def GetDateTimeMap
  ret = {}
  dparts = Builtins.filter(
    Builtins.splitstring(GetDateTime(false, false), " -:")
  ) { |v| Ops.greater_than(Builtins.size(v), 0) }

  Ops.set(ret, "year", Ops.get_string(dparts, 0, ""))
  Ops.set(ret, "month", Ops.get_string(dparts, 1, ""))
  Ops.set(ret, "day", Ops.get_string(dparts, 2, ""))
  Ops.set(ret, "hour", Ops.get_string(dparts, 3, ""))
  Ops.set(ret, "minute", Ops.get_string(dparts, 4, ""))
  Ops.set(ret, "second", Ops.get_string(dparts, 5, ""))

  Builtins.y2milestone("GetDateTimeMap dparts %1 ret %2", dparts, ret)
  deep_copy(ret)
end

- (Object) GetLanguageForTimezone(tz)

Return the language code for given timezone (by reverse searching the "language -> timezone" map)

Parameters:

  • timezone,

    if empty the current one is used



545
546
547
548
549
550
551
552
553
554
555
# File '../../src/modules/Timezone.rb', line 545

def GetLanguageForTimezone(tz)
  tz = @timezone if tz == "" || tz == nil

  lang = ""
  Builtins.foreach(get_lang2tz) do |code, tmz|
    if tmz == tz && (lang == "" || !Builtins.issubstring(lang, "_"))
      lang = code
    end
  end
  lang
end

- (Object) GetTimezoneCountry(zone)

Return translated country name of given timezone

Parameters:

  • timezone

    value (as saved in sysconfig/clock)



565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File '../../src/modules/Timezone.rb', line 565

def GetTimezoneCountry(zone)
  zmap = Convert.to_list(
    Builtins.eval(SCR.Read(path(".target.yast2"), "timezone_raw.ycp"))
  )

  sel = 0
  while Ops.less_than(sel, Builtins.size(zmap)) &&
      !Builtins.haskey(Ops.get_map(zmap, [sel, "entries"], {}), zone)
    sel = Ops.add(sel, 1)
  end
  Ops.add(
    Ops.add(Ops.get_string(zmap, [sel, "name"], ""), " / "),
    Ops.get_string(zmap, [sel, "entries", zone], zone)
  )
end

- (Object) GetTimezoneForLanguage(sys_language, default_timezone)

GetTimezoneForLanguage()

Get the timezone for the given system language.

Parameters:

  • System

    language code, e.g. “en_US”. Default timezone to be returned if nothing found.

Returns:

  • The timezone for this language, e.g. “US/Eastern” or the default value if nothing found.

See Also:

  • #-


516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File '../../src/modules/Timezone.rb', line 516

def GetTimezoneForLanguage(sys_language, default_timezone)
  # The system_language --> timezone conversion map.
  #
  lang2timezone = get_lang2tz
  ret = Ops.get(lang2timezone, sys_language, default_timezone)

  Builtins.y2milestone(
    "language %1 default timezone %2 returned timezone %3",
    sys_language,
    default_timezone,
    ret
  )
  ret
end

- (Object) Import(settings)

AutoYaST interface function: Get the Timezone configuration from a map.

Parameters:

  • settings (Hash)

    imported map

Returns:

  • success



938
939
940
941
942
943
944
945
946
947
948
949
# File '../../src/modules/Timezone.rb', line 938

def Import(settings)
  settings = deep_copy(settings)
  # Read was not called -> do the init
  PushVal() if @push == {}

  if Builtins.haskey(settings, "hwclock")
    @hwclock = Ops.get_string(settings, "hwclock", "UTC") == "UTC" ? "-u" : "--localtime"
    @user_hwclock = true
  end
  Set(Ops.get_string(settings, "timezone", @timezone), true)
  true
end

- (Object) main



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File '../../src/modules/Timezone.rb', line 32

def main
  textdomain "country"

  Yast.import "Arch"
  Yast.import "FileUtils"
  Yast.import "Language"
  Yast.import "Misc"
  Yast.import "Mode"
  Yast.import "Stage"
  Yast.import "String"
  Yast.import "ProductFeatures"

  # --------------------------------------------------------------
  # START: Globally defined data to be accessed via Timezone::<variable>
  # --------------------------------------------------------------

  @timezone = "" # e.g. "Europe/Berlin"

  # hwclock parameter
  # possible values:
  #	 ""		dont change timezone
  #	 "-u"		system clock runs UTC
  #   "--localtime"	system clock runs localtime
  @hwclock = ""

  # The default timezone if set.
  #
  @default_timezone = ""

  # Flag indicating if the user has chosen a timezone.
  # To be set from outside.
  #
  @user_decision = false
  @user_hwclock = false

  # If NTP is configured
  @ntp_used = false

  @diff = 0

  # if anyuthing was modified (currently for auto client only)
  @modified = false

  # If there is windows partition, assume that local time is used
  @windows_partition = false

  # if mkinitrd should be called at the end
  @call_mkinitrd = false

  # translation of correct timezone to the one that could be shown in map widget
  @yast2zonetab = {
    "Mideast/Riyadh87" => "Asia/Riyadh",
    "Mideast/Riyadh88" => "Asia/Riyadh",
    "Mideast/Riyadh89" => "Asia/Riyadh",
    "Europe/Vatican"   => "Europe/Rome"
  }

  # on init, translate these to correct ones
  @obsoleted_zones = {
    "Iceland"                  => "Atlantic/Reykjavik",
    "Europe/Belfast"           => "Europe/London",
    "Australia/South"          => "Australia/Adelaide",
    "Australia/North"          => "Australia/Darwin",
    "Australia/NSW"            => "Australia/Sydney",
    "Australia/ACT"            => "Australia/Canberra",
    "Australia/Queensland"     => "Australia/Brisbane",
    "Australia/Tasmania"       => "Australia/Hobart",
    "Australia/Victoria"       => "Australia/Melbourne",
    "Australia/West"           => "Australia/Perth",
    "US/Alaska"                => "America/Anchorage",
    "US/Aleutian"              => "America/Adak",
    "US/Arizona"               => "America/Phoenix",
    "US/Central"               => "America/Chicago",
    "US/East-Indiana"          => "America/Indiana/Indianapolis",
    "US/Hawaii"                => "Pacific/Honolulu",
    "US/Indiana-Starke"        => "America/Indiana/Knox",
    "US/Michigan"              => "America/Detroit",
    "US/Mountain"              => "America/Denver",
    "US/Pacific"               => "America/Los_Angeles",
    "US/Samoa"                 => "Pacific/Pago_Pago",
    "US/Eastern"               => "America/New_York",
    "Canada/Atlantic"          => "America/Halifax",
    "Canada/Central"           => "America/Winnipeg",
    "Canada/Eastern"           => "America/Toronto",
    "Canada/Saskatchewan"      => "America/Regina",
    "Canada/East-Saskatchewan" => "America/Regina",
    "Canada/Mountain"          => "America/Edmonton",
    "Canada/Newfoundland"      => "America/St_Johns",
    "Canada/Pacific"           => "America/Vancouver",
    "Canada/Yukon"             => "America/Whitehorse",
    "America/Buenos_Aires"     => "America/Argentina/Buenos_Aires",
    "America/Virgin"           => "America/St_Thomas",
    "Brazil/Acre"              => "America/Rio_Branco",
    "Brazil/East"              => "America/Sao_Paulo",
    "Brazil/West"              => "America/Manaus",
    "Chile/Continental"        => "America/Santiago",
    "Chile/EasterIsland"       => "Pacific/Easter",
    "Mexico/BajaNorte"         => "America/Tijuana",
    "Mexico/BajaSur"           => "America/Mazatlan",
    "Mexico/General"           => "America/Mexico_City",
    "Jamaica"                  => "America/Jamaica",
    "Asia/Macao"               => "Asia/Macau",
    "Israel"                   => "Asia/Jerusalem",
    "Asia/Tel_Aviv"            => "Asia/Jerusalem",
    "Hongkong"                 => "Asia/Hong_Kong",
    "Japan"                    => "Asia/Tokyo",
    "ROK"                      => "Asia/Seoul",
    "Africa/Timbuktu"          => "Africa/Bamako",
    "Egypt"                    => "Africa/Cairo"
  }
  # ------------------------------------------------------------------
  # END: Globally defined data to be accessed via Timezone::<variable>
  # ------------------------------------------------------------------



  # ------------------------------------------------------------------
  # START: Locally defined data
  # ------------------------------------------------------------------

  # internal map used to store initial data
  @push = {}


  @name = ""

  # list with maps, each map provides time zone information about one region
  @zonemap = []

  # 'language --> default timezone' conversion map
  @lang2tz = {}

  # remember if /sbin/hwclock --hctosys was called, it can be done only once (bnc#584484)
  @systz_called = false
  Timezone()
end

- (Array) MakeProposal(force_reset, language_changed)

Return proposal list of strings.

If force_reset is true reset the module to the timezone stored in default_timezone.

Parameters:

  • force_reset (Boolean)

    boolean language_changed

Returns:

  • (Array)

    user readable description.



669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
# File '../../src/modules/Timezone.rb', line 669

def MakeProposal(force_reset, language_changed)
  Builtins.y2milestone("force_reset: %1", force_reset)
  Builtins.y2milestone(
    "language_changed: %1 user_decision %2 user_hwclock %3",
    language_changed,
    @user_decision,
    @user_hwclock
  )

  ResetZonemap() if language_changed

  if !@user_hwclock || force_reset
    @hwclock = "-u"
    @hwclock = "--localtime" if ProposeLocaltime()
  end
  if force_reset
    # If user wants to reset do it if a default is available.
    #
    if @default_timezone != ""
      Set(@default_timezone, true) # reset
    end

    # Reset user_decision flag.
    #
    @user_decision = false # no reset
  else
    # Only follow the language if the user has never actively chosen
    # a timezone. The indicator for this is user_decision which is
    # set from outside the module.
    #
    if @user_decision || Mode.autoinst ||
        ProductFeatures.GetStringFeature("globals", "timezone") != ""
      if language_changed
        Builtins.y2milestone(
          "User has chosen a timezone; not following language - only retranslation."
        )

        Set(@timezone, true)
      end
    else
      # User has not yet chosen a timezone ==> follow language.
      #
      local_timezone = GetTimezoneForLanguage(
        Language.language,
        "US/Eastern"
      )

      if local_timezone != ""
        Set(local_timezone, true)
        @default_timezone = local_timezone
      else
        if language_changed
          Builtins.y2error("Can't follow language - only retranslation")

          Set(@timezone, true)
        end
      end
    end
  end

  # label text (Clock setting)
  clock_setting = _("UTC")

  if @hwclock == "--localtime"
    # label text, Clock setting: local time (not UTC)
    clock_setting = _("Local Time")
  end

  # label text
  clock_setting = Ops.add(_("Hardware Clock Set To") + " ", clock_setting)

  date = GetDateTime(true, true)

  Builtins.y2milestone("MakeProposal hwclock %1", @hwclock)

  ret = [
    Ops.add(
      Ops.add(Ops.add(Ops.add(@name, " - "), clock_setting), " "),
      date
    )
  ]
  if @ntp_used
    # summary label
    ret = Builtins.add(ret, _("NTP configured"))
  end
  deep_copy(ret)
end

- (Object) Modified

was anything modified?



930
931
932
933
# File '../../src/modules/Timezone.rb', line 930

def Modified
  @modified || @timezone != Ops.get_string(@push, "timezone", @timezone) ||
    @hwclock != Ops.get_string(@push, "hwclock", @hwclock)
end

- (Object) PopVal

restore the original data from internal map



907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
# File '../../src/modules/Timezone.rb', line 907

def PopVal
  Builtins.y2milestone(
    "before Pop: timezone %1 hwclock %2",
    @timezone,
    @hwclock
  )
  if Builtins.haskey(@push, "hwclock")
    @hwclock = Ops.get_string(@push, "hwclock", @hwclock)
  end
  if Builtins.haskey(@push, "timezone")
    @timezone = Ops.get_string(@push, "timezone", @timezone)
  end
  @push = {}
  Builtins.y2milestone(
    "after Pop: timezone %1 hwclock %2",
    @timezone,
    @hwclock
  )

  nil
end

- (Object) ProposeLocaltime

Return true if localtime should be proposed as default Based on current hardware configuration: Win partitions present or 32bit Mac



655
656
657
# File '../../src/modules/Timezone.rb', line 655

def ProposeLocaltime
  @windows_partition || Arch.board_mac && Arch.ppc32
end

- (Object) PushVal

save the initial data



899
900
901
902
903
904
# File '../../src/modules/Timezone.rb', line 899

def PushVal
  @push = { "hwclock" => @hwclock, "timezone" => @timezone }
  Builtins.y2milestone("PushVal map %1", @push)

  nil
end

- (Object) Read

Read timezone settings from sysconfig



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File '../../src/modules/Timezone.rb', line 359

def Read
  @timezone = Misc.SysconfigRead(
    path(".sysconfig.clock.TIMEZONE"),
    @timezone
  )
  @default_timezone = Misc.SysconfigRead(
    path(".sysconfig.clock.DEFAULT_TIMEZONE"),
    @default_timezone
  )

  # /etc/localtime has priority over sysconfig value of timezone
  if FileUtils.IsLink("/etc/localtime")
    tz_file = Convert.to_string(
      SCR.Read(path(".target.symlink"), "/etc/localtime")
    )
    if tz_file != nil &&
        Builtins.substring(tz_file, 0, 20) == "/usr/share/zoneinfo/"
      @timezone = Builtins.substring(tz_file, 20)
      Builtins.y2milestone(
        "time zone read from /etc/localtime: %1",
        @timezone
      )
    end
  end

  adjtime = ReadAdjTime()
  if Builtins.size(adjtime) == 3
    if Ops.get(adjtime, 2, "") == "LOCAL"
      @hwclock = "--localtime"
    elsif Ops.get(adjtime, 2, "") == "UTC"
      @hwclock = "-u"
    end
    Builtins.y2milestone("content of /etc/adjtime: %1", adjtime)
  else
    # use sysconfig value as a backup (if available)
    @hwclock = Misc.SysconfigRead(
      path(".sysconfig.clock.HWCLOCK"),
      @hwclock
    )
  end

  # get name for cloning purposes
  if Mode.config
    zmap = get_zonemap
    sel = 0
    while Ops.less_than(sel, Builtins.size(zmap)) &&
        !Builtins.haskey(Ops.get_map(zmap, [sel, "entries"], {}), @timezone)
      sel = Ops.add(sel, 1)
    end
    @name = Ops.add(
      Ops.add(Ops.get_string(zmap, [sel, "name"], ""), " / "),
      Ops.get_string(zmap, [sel, "entries", @timezone], @timezone)
    )
  end

  nil
end

- (Object) ReadAdjTime

Read the content of /etc/adjtime



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File '../../src/modules/Timezone.rb', line 341

def ReadAdjTime
  cont = Convert.convert(
    SCR.Read(path(".etc.adjtime")),
    :from => "any",
    :to   => "list <string>"
  )
  if cont == nil
    Builtins.y2warning("/etc/adjtime not available or not readable")
  end
  if Builtins.size(cont) != 3
    Builtins.y2warning("/etc/adjtime has wrong number of lines: %1", cont)
    cont = nil
  end
  deep_copy(cont)
end

- (Object) Region

Return list of regions for timezone selection list



794
795
796
797
798
799
800
# File '../../src/modules/Timezone.rb', line 794

def Region
  num = -1
  Builtins.maplist(get_zonemap) do |entry|
    num = Ops.add(num, 1)
    Item(Id(num), Ops.get_string(entry, "name", ""), false)
  end
end

- (Object) ResetZonemap

Clear the internal map with timezones, so the timezone data could be retranslated next time when they are needed



646
647
648
649
650
# File '../../src/modules/Timezone.rb', line 646

def ResetZonemap
  @zonemap = []

  nil
end

- (Object) Save

Save()

Save timezone to target sysconfig.



806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
# File '../../src/modules/Timezone.rb', line 806

def Save
  if Mode.mode == "update"
    Builtins.y2milestone("not saving in update mode...")
    return
  end

  SCR.Write(path(".sysconfig.clock.TIMEZONE"), @timezone)
  SCR.Write(path(".sysconfig.clock.DEFAULT_TIMEZONE"), @default_timezone)

  SCR.Write(path(".sysconfig.clock"), nil) # flush

  Builtins.y2milestone("Save Saved data for timezone: <%1>", @timezone)

  adjtime = ReadAdjTime()
  if adjtime.nil? || adjtime.size == 3
    new     = adjtime.nil? ? ["0.0 0 0.0", "0"] : adjtime.dup
    new[2]  = @hwclock == "-u" ? "UTC" : "LOCAL"
    if new[2] != adjtime[2]
      SCR.Write(path(".etc.adjtime"), new)
      Builtins.y2milestone("Saved /etc/adjtime with '%1'", new[2])
    end
  end

  CallMkinitrd() if @call_mkinitrd && !Stage.initial

  nil
end

- (Hash) Selection(num)

Selection()

Return a map of ids and names to build up a selection list for the user. The key is used later in the Set function to select this timezone. The name is a translated string.

Parameters:

  • -

Returns:

  • (Hash)

    map for timezones 'timezone_id' is used internally in Set and Probe functions. 'timezone_name' is a user-readable string. Uses Language::language for translation.

See Also:

  • #Set()


771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
# File '../../src/modules/Timezone.rb', line 771

def Selection(num)
  zmap = get_zonemap

  trl = Builtins.maplist(Ops.get_map(zmap, [num, "entries"], {})) do |key, name|
    [name, key]
  end

  trl = Builtins.sort(trl) do |a, b|
    # bnc#385172: must use < instead of <=, the following means:
    # strcoll(x) <= strcoll(y) && strcoll(x) != strcoll(y)
    lsorted = Builtins.lsort([Ops.get(a, 0, ""), Ops.get(b, 0, "")])
    lsorted_r = Builtins.lsort([Ops.get(b, 0, ""), Ops.get(a, 0, "")])
    Ops.get_string(lsorted, 0, "") == Ops.get(a, 0, "") &&
      lsorted == lsorted_r
  end
  Builtins.y2debug("trl = %1", trl)

  Builtins.maplist(trl) do |e|
    Item(Id(Ops.get_string(e, 1, "")), Ops.get_string(e, 0, ""), false)
  end
end

- (Object) Set(zone, really)

——————————————————————

END: Locally defined functions

Set()

Set system to selected timezone.

Parameters:

  • string

    timezone to select, e.g. “Europe/Berlin”

Returns:

  • the number of the region that contains the timezone



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File '../../src/modules/Timezone.rb', line 247

def Set(zone, really)
  zmap = get_zonemap

  # Set the new timezone internally
  @timezone = zone

  sel = 0
  while Ops.less_than(sel, Builtins.size(zmap)) &&
      !Builtins.haskey(Ops.get_map(zmap, [sel, "entries"], {}), zone)
    sel = Ops.add(sel, 1)
  end

  @name = Ops.add(
    Ops.add(Ops.get_string(zmap, [sel, "name"], ""), " / "),
    Ops.get_string(zmap, [sel, "entries", zone], zone)
  )

  # Adjust system to the new timezone.
  #
  if !Mode.config && really
    textmode = Language.GetTextMode
    # turn off the screensaver when clock can change radically (bnc#455771)
    # (in non-firstboot cases, installation process handles it)
    if Stage.firstboot && !textmode
      SCR.Execute(path(".target.bash"), "/usr/bin/xset -dpms")
      SCR.Execute(path(".target.bash"), "/usr/bin/xset s reset")
      SCR.Execute(path(".target.bash"), "/usr/bin/xset s off")
    end
    cmd = Ops.add("/usr/sbin/zic -l ", @timezone)
    Builtins.y2milestone("Set cmd %1", cmd)
    Builtins.y2milestone(
      "Set ret %1",
      SCR.Execute(path(".target.bash_output"), cmd)
    )
    cmd = "/bin/systemctl try-restart systemd-timedated.service"
    Builtins.y2milestone(
      "restarting timedated service: %1",
      SCR.Execute(path(".target.bash_output"), cmd)
    )
    if !Arch.s390
      cmd = Ops.add("/sbin/hwclock --hctosys ", @hwclock)
      if Stage.initial && @hwclock == "--localtime"
        if !@systz_called
          cmd = "/sbin/hwclock --systz --localtime --noadjfile && touch /dev/shm/warpclock"
          @systz_called = true
        end
      end
      Builtins.y2milestone("Set cmd %1", cmd)
      Builtins.y2milestone(
        "Set ret %1",
        SCR.Execute(path(".target.bash_output"), cmd)
      )
    end
    if Stage.firstboot && !textmode
      SCR.Execute(path(".target.bash"), "/usr/bin/xset s on")
      SCR.Execute(path(".target.bash"), "/usr/bin/xset +dpms")
    end
  end

  # On first assignment store default timezone.
  #
  if @default_timezone == ""
    @default_timezone = @timezone
    Builtins.y2milestone("Set default timezone: <%1>", @timezone)
  end

  Builtins.y2milestone(
    "Set timezone:%1 sel:%2 name:%3",
    @timezone,
    sel,
    @name
  )
  sel
end

- (Object) SetTime(year, month, day, hour, minute, second)

Set the new time and date given by user



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File '../../src/modules/Timezone.rb', line 456

def SetTime(year, month, day, hour, minute, second)
  if !Arch.s390
    date = Builtins.sformat(
      " --date=\"%1/%2/%3 %4:%5:%6\" ",
      month,
      day,
      year,
      hour,
      minute,
      second
    )
    cmd = ""
    if Ops.greater_than(Builtins.size(@timezone), 0) &&
        @hwclock != "--localtime"
      cmd = Ops.add(Ops.add("TZ=", @timezone), " ")
    end
    cmd = Ops.add(
      Ops.add(Ops.add(cmd, "/sbin/hwclock --set "), @hwclock),
      date
    )
    Builtins.y2milestone("SetTime cmd %1", cmd)
    SCR.Execute(path(".target.bash"), cmd)
    cmd = Ops.add("/sbin/hwclock --hctosys ", @hwclock)
    Builtins.y2milestone("SetTime cmd %1", cmd)
    SCR.Execute(path(".target.bash"), cmd)
    # actually, it was probably not called, but do not let it change the time again after manual change
    @systz_called = true
  end

  nil
end

- (Object) SetTimezoneForLanguage(sys_language)

Set the timezone for the given system language.

Parameters:

  • System

    language code, e.g. “en_US”.

Returns:

  • the number of the region that contains the timezone



534
535
536
537
538
539
540
# File '../../src/modules/Timezone.rb', line 534

def SetTimezoneForLanguage(sys_language)
  tmz = GetTimezoneForLanguage(sys_language, "US/Eastern")
  Builtins.y2debug("language %1 proposed timezone %2", sys_language, tmz)
  Set(tmz, true) if tmz != ""

  nil
end

- (Object) Summary

AutoYaST interface function: Return the summary of Timezone configuration as a map.

Returns:

  • summary string (html)



963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
# File '../../src/modules/Timezone.rb', line 963

def Summary
  Yast.import "HTML"

  clock_setting = _("UTC")

  if @hwclock == "--localtime"
    # label text, Clock setting: local time (not UTC)
    clock_setting = _("Local Time")
  end

  # label text
  clock_setting = Ops.add(_("Hardware Clock Set To") + " ", clock_setting)

  ret = [
    # summary label
    Builtins.sformat(_("Current Time Zone: %1"), @name),
    clock_setting
  ]
  HTML.List(ret)
end

- (Object) SystemTime2HWClock

Set the Hardware Clock to the current System Time.



489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File '../../src/modules/Timezone.rb', line 489

def SystemTime2HWClock
  if !Arch.s390
    cmd = ""
    if Ops.greater_than(Builtins.size(@timezone), 0) &&
        @hwclock != "--localtime"
      cmd = Ops.add(Ops.add("TZ=", @timezone), " ")
    end
    cmd = Ops.add("/sbin/hwclock --systohc ", @hwclock)
    Builtins.y2milestone("cmd %1", cmd)
    SCR.Execute(path(".target.bash"), cmd)
  end

  nil
end

- (Object) Timezone

Timezone()

The module constructor. Sets the proprietary module data defined globally for public access. This is done only once (and automatically) when the module is loaded for the first time. Calls Set() in initial mode. Reads current timezone from sysconfig in normal mode.

See Also:

  • #Set()


426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File '../../src/modules/Timezone.rb', line 426

def Timezone
  # Set default values.
  #
  @hwclock = "-u"
  if Stage.initial && !Mode.live_installation
    # language --> timezone database, e.g. "de_DE" : "Europe/Berlin"
    lang2tz = get_lang2tz

    new_timezone = Ops.get(lang2tz, Language.language, "")
    Builtins.y2milestone("Timezone new_timezone %1", new_timezone)

    Set(new_timezone, true) if new_timezone != ""
  elsif !Mode.config
    Read()
  end
  nil
end

- (Object) UpdateTimezone(tmz)

Convert the duplicated timezone to the only one supported Temporary solution - a result of discussion of bug #47472

Parameters:

  • tmz (String)

    current timezone



325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File '../../src/modules/Timezone.rb', line 325

def UpdateTimezone(tmz)
  updated_tmz = tmz

  if Builtins.haskey(@obsoleted_zones, tmz)
    updated_tmz = Ops.get(@obsoleted_zones, tmz, tmz)
    Builtins.y2milestone(
      "updating timezone from %1 to %2",
      tmz,
      updated_tmz
    )
  end

  updated_tmz
end

- (Object) utc_only

does the hwclock run on UTC only ? -> skip asking



886
887
888
889
890
891
892
893
894
895
896
# File '../../src/modules/Timezone.rb', line 886

def utc_only
  Builtins.y2milestone(
    "Arch::sparc () %1 Arch::board_iseries () %2 Arch::board_chrp () %3 Arch::board_prep () %4",
    Arch.sparc,
    Arch.board_iseries,
    Arch.board_chrp,
    Arch.board_prep
  )

  Arch.sparc || Arch.board_iseries || Arch.board_chrp || Arch.board_prep
end