Skip to content

Commit

Permalink
Merge pull request #243 from wordpress-mobile/release/1.8.12
Browse files Browse the repository at this point in the history
Release/1.8.12
  • Loading branch information
loremattei authored Jan 27, 2020
2 parents ff14814 + 8d96d43 commit 6b99019
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion WordPressShared.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressShared"
s.version = "1.8.11"
s.version = "1.8.12"
s.summary = "Shared components used in building the WordPress iOS apps and other library components."

s.description = <<-DESC
Expand Down
1 change: 1 addition & 0 deletions WordPressShared/Core/Analytics/WPAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ typedef NS_ENUM(NSUInteger, WPAnalyticsStat) {
WPAnalyticsStatOpenedSupport,
WPAnalyticsStatOpenedViewAdmin,
WPAnalyticsStatOpenedViewSite,
WPAnalyticsStatOpenedWebPreview,
WPAnalyticsStatPerformedCoreDataMigrationFixFor45,
WPAnalyticsStatPersonUpdated,
WPAnalyticsStatPersonRemoved,
Expand Down
16 changes: 13 additions & 3 deletions WordPressShared/Core/Utility/NSDate+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,21 @@ extension Date {

/// Formats the current date as relative date if it's within a week of
/// today, or with DateFormatter.Style.medium otherwise.
/// - Parameter timeZone: An optional time zone used to adjust the date formatters. **NOTE**: This has no affect on relative time stamps.
///
/// - Example: 22 hours from now
/// - Example: 5 minutes ago
/// - Example: 8 hours ago
/// - Example: 2 days ago
/// - Example: Jan 22, 2017
///
public func mediumString() -> String {
public func mediumString(timeZone: TimeZone? = nil) -> String {
let relativeFormatter = TTTTimeIntervalFormatter()
let absoluteFormatter = DateFormatters.mediumDate

if let timeZone = timeZone {
absoluteFormatter.timeZone = timeZone
}

let components = Calendar.current.dateComponents([.day], from: self, to: Date())
if let days = components.day, abs(days) < 7 {
Expand All @@ -139,15 +144,20 @@ extension Date {
}

/// Formats the current date as a medium relative date/time.
/// - Parameter timeZone: An optional time zone used to adjust the date formatters.
///
/// - Example: Tomorrow, 6:45 AM
/// - Example: Today, 8:09 AM
/// - Example: Yesterday, 11:36 PM
/// - Example: Jan 28, 2017, 1:51 PM
/// - Example: Jan 22, 2017, 2:18 AM
///
public func mediumStringWithTime() -> String {
return DateFormatters.mediumDateTime.string(from: self)
public func mediumStringWithTime(timeZone: TimeZone? = nil) -> String {
let formatter = DateFormatters.mediumDateTime
if let timeZone = timeZone {
formatter.timeZone = timeZone
}
return formatter.string(from: self)
}

/// Formats the current date as (non relative) long date (no time) in UTC.
Expand Down
15 changes: 7 additions & 8 deletions WordPressShared/Core/Views/WPStyleGuide+DynamicType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,13 @@ extension WPStyleGuide {
/// - Returns: the requested scaled font.
///
private class func scaledFont(for style: UIFont.TextStyle, weight: UIFont.Weight) -> UIFont {
let traitCollection = UITraitCollection(preferredContentSizeCategory: .large)
let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style, compatibleWith: traitCollection)

let traits = [UIFontDescriptor.TraitKey.weight: UIFont.Weight.semibold]
let descriptorWithTraits = descriptor.addingAttributes([.traits: traits])
let baseFontWithTraits = UIFont(descriptor: descriptorWithTraits, size: 0)

return UIFontMetrics(forTextStyle: style).scaledFont(for: baseFontWithTraits)
let font = UIFont.preferredFont(forTextStyle: style)
let traits = [UIFontDescriptor.TraitKey.weight: weight]

let descriptorWithTraits = font.fontDescriptor.addingAttributes([.traits: traits])
let size = UIFontMetrics(forTextStyle: style).scaledValue(for: font.pointSize)

return UIFont(descriptor: descriptorWithTraits, size: size)
}

/// Creates a NotoSerif UIFont for the user current text size settings.
Expand Down
29 changes: 29 additions & 0 deletions WordPressSharedTests/NSDateHelperTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,33 @@ class NSDateHelperTest: XCTestCase {
XCTAssertEqual(components.month, data.month)
XCTAssertEqual(components.day, data.day)
}

/// Verifies that `mediumString` produces relative format strings when less than 7 days have elapsed.
func testMediumStringRelativeString() {
let date = Date()
XCTAssertEqual(date.mediumString(), "just now")
XCTAssertEqual(date.addingTimeInterval(-60*5).mediumString(), "5 minutes ago")
XCTAssertEqual(date.addingTimeInterval(-60*60*2).mediumString(), "2 hours ago")
XCTAssertEqual(date.addingTimeInterval(-60*60*24).mediumString(), "1 day ago")
XCTAssertEqual(date.addingTimeInterval(-60*60*24*6).mediumString(), "6 days ago")
}

/// Verifies that `mediumStringWithTime` takes into account the time zone adjustment
func testMediumStringTimeZoneAdjust() {
let date = Date()
let timeZone = TimeZone(secondsFromGMT: Calendar.current.timeZone.secondsFromGMT() - (60 * 60))
XCTAssertEqual(date.mediumString(timeZone: timeZone), "just now")

let timeFormatter = DateFormatter()
timeFormatter.dateStyle = .none
timeFormatter.timeStyle = .short
let withoutTimeZoneAdjust = timeFormatter.string(from: date)

XCTAssertEqual(date.mediumStringWithTime(), "Today at \(withoutTimeZoneAdjust)")

timeFormatter.timeZone = timeZone
let withTimeZoneAdjust = timeFormatter.string(from: date)

XCTAssertEqual(date.mediumStringWithTime(timeZone: timeZone), "Today at \(withTimeZoneAdjust)")
}
}

0 comments on commit 6b99019

Please sign in to comment.