* Fix parsing foreign currency strings
Currently parsing a currency string would fail if the currency code does not match `FormatStyle`'s locale region. For example,
```swift
let style = Decimal.FormatStyle.Currency(code: "GBP", locale: .init(identifier: "en_US")).presentation(.isoCode)
```
This formats 3.14 into "GBP\u{0xa0}3.14", but parsing such string fails.
Fix this by always set the ICU formatter's currency code.
Resolves rdar://138179737
* Update the test to throw properly instead of force unwrap
* Remove another force try
* Remove the stored `numberFormatType` and `locale` inside `IntegerParseStrategy` and `FloatingPointParseStrategy`
These properties are redundant as the information is already available through the public variable `formatStyle`.
* Address feedback
* Fix a typo
* Add ProcessInfo implementations for other platforms
* Update Platform.getHostname for Windows
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
* Add alternate platform implementations of ProcessInfo tests
* Clean up windows switch statement
* Use nonzeroBitCount on Windows
* Add Linux implementation for retrieving active processor count
* Apply Windows additions from code review
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
* Apply additional Windows suggestions
* TotalMemoryKB -> totalMemoryKB
* Fix conditional os directive
* Update process name
---------
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
We started getting errors about duplicated symbols now that `DiscreteFormatStyle` has landed in SDK. Workaround this by adding a typealias like other types.
* (123438249) FileManager.removeItem does not throw error when encoutering long paths
The change makes swift-foundation FileManager.removeItem properly throw
on removefile(3) errors.
* Conform POSIXError to Error
* Clean up warnings and produce more detailed test failures
* Fix macOS CI failure
- Fix precision issues around nanoseconds calculation.
Update test expectations.
- Lessen the chance of overflowing `func add(:)` by using `Double`
We eventually convert to Double before return anyways.
- Disable TestDateComponentsDiscreteConformance.testRandomSamples temporarily for 32-bit platforms
This test triggers code path that has wrong assumption on Calendar API's return value, and overflows when the input dates are distant from each other. Disable it for now. Will track the fix in 123262305
Resolves 121677598
* WIP Gregorian Calendar in FoundationEssentials
Implement `dateComponents(from date:)`. The implementation largely follows that of ICU in calendar.cpp and gregocal.cpp. Julian day calculation algorithm is referenced [The Explanatory Supplement to the Astronomical Almanac](https://aa.usno.navy.mil/publications/exp_supp).
First, calculate the Julian day number from a given `Date`. Then, convert the Julian day number to Gregorian calendar date fields[^1]. The remaining part is the time within the day.
There are a few things to look out for
- Julian day starts at noon, while `Date` uses midnight as the reference time, so we need to adjust it acccordingly at every conversion. Note that ICU uses Modified Julian Day number throughout their codebase, which starts at midnight, so
- Dates close to Gregorian calendar adoption, which is also referred as "cutover" or "transition" date interchangeably, needs to be handled with care. Date before the adoption date were represented in Julian Calendar and Gregorian Calendar after the adoption date. The common Gregorian Calendar adoption date is Friday, 15 October 1582. It's also customizable in the API.
- The week number of a month and a year depends on `firstWeekday` and `minimumDaysInFirstWeek` values. The week starts at `firstWeekday`. Week one must contain `minimumDaysInFirstWeek` number of days.
[^1]: A nice readable version of the Julain - Gregorian converting algorithm: https://en.wikipedia.org/wiki/Julian_day#Julian_day_number_calculation.
* Disable a test that's not available until we implement the function in `GregorianCalendar`.
* Add a precondition for first weekday setter instead of silently dropping the value
* Gregorian Calendar part 2: Implement `date(from components:)`.
The implementation largely follows that of ICU. The logic follows this pattern generally
- Calculate the Julian day number from a given year, month, day of month number
- Add time field values if they are set
- Adjust for timezone offset
The complexity lies in the following situations
(1) The passed-in date components lacks essential fields to determine the Julian day number
(2) The date components has week-related fields set, but no year, month, day of month fields set
(3) The date components has both week-related fields and month, day of month fields set
(4) The day is near Gregorian calendar transition date
For (1), simply assume the start of the year/month/day if the field is missing. The value would be either 0 or 1, depending on if it's 0 or 1 indexed.
For (2), calculate the julian day of the start of the month. Advance by multiples of the given week number.
For (3), we need to determine which fields take over precedence of others. ICU tracks the order of when the fields are modified; newly modified ones always take precedence over past ones. We have not been using this mechanism at all in existing Calendar_ICU's implementation. Instead we've been setting the fields arbitrarily. Therefore, here we simplify ICU's heuristics by assuming the timestamps of modified fields are all equal.
For (4), recalculate the date using Julian calendar if the found date is before Gregorian transition date.
* rdar://106770688 (Port test/stdlib/NSStringAPI.swift from the Swift repo)
Batch add `String` and `Substring` tests for from stdlib to FCF. These were removed from stldlib in https://github.com/apple/swift/pull/67252/files and https://github.com/apple/swift/pull/67450/. These tests were added to test Foundation's `StringProtocol` extension that called into `NSString` API.
Now that some of the tests were implemented with Swift natively, they should be made available for FoundationPreview, but we'll track that in a separate PR.
* Address review feedback: clean up availability annotations
* Remove the need of swizzling current locale. Instead, add internal functions those localized functions can call into and pass in a locale explicitly for testing.
* Remove the use of current locale in tests
* (101354563) Separate CodableWithConfiguration into standalone file
* (101354563) Update PredicateExpression archive formats
* (101354563) Codable Support for Predicate
* (101354563) Assert on unsupported keypaths