blob: aaa81852011511d1d70826e4eb3738b6b835a67b [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "tz_version.h"
#include <iostream>
#include <sstream>
#include "common.h"
#include "src/lib/fxl/command_line.h"
#include "src/lib/icu/tools/extractor/icu_headers.h"
namespace icu_data_extractor {
namespace {
constexpr const char kName[] = "tz-version";
constexpr ssize_t kMinTzVersionLength = 5;
} // namespace
std::string_view TzVersion::Name() const { return kName; }
int TzVersion::Execute(const fxl::CommandLine& command_line,
const fxl::CommandLine& sub_command_line) const {
UErrorCode err = U_ZERO_ERROR;
const char* version = icu::TimeZone::getTZDataVersion(err);
if (err != U_ZERO_ERROR) {
std::cerr << "Error: " << u_errorName(err) << std::endl;
return -1;
}
if (strlen(version) < kMinTzVersionLength) {
std::cerr << "Bad tz version string: " << version << std::endl;
return -1;
}
return WriteToOutputFileOrStdOut(sub_command_line, std::string(version));
}
void TzVersion::PrintDocs(std::ostream& os) const {
os << " " << kName << "\n --" << kArgOutputPath
<< "=FILE\t\t\tPath to output file (if omitted, STDOUT)"
<< "\n\n Extract the time zone version string, e.g. \"2019c\"";
}
} // namespace icu_data_extractor