Skip to content

Commit

Permalink
Honor default timezone when using read-only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Dec 9, 2016
1 parent e387770 commit 8c95457
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 12 additions & 2 deletions timezone/src/modules/Timezone.rb
Expand Up @@ -16,7 +16,7 @@
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# curhttps://github.com/yast/yast-country/pull/97rent contact information at www.novell.com.
# ------------------------------------------------------------------------------
# File: modules/Timezone.ycp
# Package: Country settings
Expand Down Expand Up @@ -445,7 +445,7 @@ def Timezone
# language --> timezone database, e.g. "de_DE" : "Europe/Berlin"
new_timezone =
if readonly
"UTC"
product_default_timezone
else
lang2tz = get_lang2tz
Ops.get(lang2tz, Language.language, "")
Expand Down Expand Up @@ -1008,6 +1008,16 @@ def readonly
@readonly ||= ProductFeatures.GetBooleanFeature("globals", "readonly_timezone")
end

# Determines the default timezone for the current product
#
# If not timezone is set, "UTC" will be used.
#
# @return [String] timezone
def product_default_timezone
product_timezone = ProductFeatures.GetStringFeature("globals", "timezone")
product_timezone.empty? ? "UTC" : product_timezone
end

publish :variable => :timezone, :type => "string"
publish :variable => :hwclock, :type => "string"
publish :variable => :default_timezone, :type => "string"
Expand Down
13 changes: 13 additions & 0 deletions timezone/test/Timezone_test.rb
Expand Up @@ -3,14 +3,18 @@
require_relative "test_helper"

Yast.import "Timezone"
Yast.import "ProductFeatures"

describe Yast::Timezone do
let(:readonly_timezone) { false }
let(:default_timezone) { "" }
let(:initial) { false }

before do
allow(Yast::ProductFeatures).to receive(:GetBooleanFeature)
.with("globals", "readonly_timezone").and_return(readonly_timezone)
allow(Yast::ProductFeatures).to receive(:GetStringFeature)
.with("globals", "timezone").and_return(default_timezone)
allow(Yast::Stage).to receive(:initial).and_return(initial)
Yast::Timezone.main
end
Expand Down Expand Up @@ -57,13 +61,22 @@
end

describe "#timezone" do

context "when timezone is read-only during installation" do
let(:readonly_timezone) { true }
let(:initial) { true }

it "returns 'UTC'" do
expect(subject.timezone).to eq("UTC")
end

context "and default timezone is set" do
let(:default_timezone) { "Atlantic/Canary" }

it "returns the default timezone" do
expect(subject.timezone).to eq("Atlantic/Canary")
end
end
end
end

Expand Down

0 comments on commit 8c95457

Please sign in to comment.