35 Commits

Author SHA1 Message Date
Tina Liu
e9d59b6065
Fix parsing foreign currency strings (#1074)
* 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
2025-01-16 08:41:59 -08:00
Charles Hu
9d57f36de7
Re-enable disabled tests due to ICU-74 (#890)
resolves: rdar://121399858
2024-08-29 14:06:27 -07:00
Tony Parker
caa08cf226
Enable complete concurrency checking in Foundation 2024-06-04 10:41:59 -07:00
Jonathan Flat
361efcf5fe
Port URL and URLComponents to swift-foundation (#586) 2024-05-06 09:51:18 -07:00
Jeremy Schonfeld
ad9d6d4d7a
(127135444) Add ProcessInfo implementations for other platforms (#559)
* 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>
2024-04-29 15:35:18 -07:00
Jeremy Schonfeld
499646b670
(125912926) Remove SPI annotations from Expression (#549) 2024-04-17 08:50:41 -07:00
Jeremy Schonfeld
21f877a540
(125885524) Temporarily mark Expression as SPI 2024-04-09 09:28:40 -07:00
Jeremy Schonfeld
2ecaed1e6c
(122026982) Introduce #Expression macro and type
* (122026982) Introduce #Expression macro and type

* (122026982) Add radar to comments
2024-03-26 14:06:16 -07:00
Jeremy Schonfeld
c1e5321e8d
(125120887) attributesForItem(atPath:) uses FileAttributeType instead of String for .type value 2024-03-21 15:51:16 -07:00
Tina Liu
71cf0809cc
There's no FoundationEssentials when building with FOUNDATION_FRAMEWORK (#475) 2024-03-12 16:09:10 -07:00
Tina Liu
e1e3d2fcb3
Duplicated DiscreteFormatStyle error in test (#472)
We started getting errors about duplicated symbols now that `DiscreteFormatStyle` has landed in SDK. Workaround this by adding a typealias like other types.
2024-03-11 09:22:05 -07:00
Tony Parker
0be1758b4f Various fixes to make PropertyListEncoder and PropertyListDecoder build cross-platform 2024-03-06 15:57:33 -08:00
Tony Parker
3e27fc7a24
Port IndexPath to FoundationEssentials (#445) 2024-03-01 10:21:28 -08:00
Jeremy Schonfeld
beeea05206
(123438249) FileManager.removeItem does not throw error when encountering long paths
* (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
2024-02-28 13:33:55 -08:00
Tina Liu
466549386b
Use _CalendarGregorian as the backing calendar for struct Calendar (#430)
- 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
2024-02-28 11:12:37 -08:00
Max Obermeier
c4fa869c60
Implementation for "The DiscreteFormatStyle Protocol" proposal (#416)
* initial commit

* fix linux build issue

* address review

* address review

* synchronize test utilities

* disable Duration DiscreteFormatStyle tests for 32 bit machines
2024-02-16 20:34:26 -08:00
Jeremy Schonfeld
33856a556d
(120741818) Port FileManager to swift-foundation
* (120741818) Port FileManager to swift-foundation

* (120741818) Fix linux test failures

* (120741818) Fix build failures
2024-02-09 15:03:43 -08:00
Charles Hu
c6f774ff6f
Update FoundationICU to 0.0.4 (#304) 2023-12-07 10:40:19 -08:00
Tina Liu
cd3d29426f
WIP Gregorian Calendar in FoundationEssentials (#303)
* 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.
2023-11-02 16:33:46 -07:00
Tony Parker
85ddb1373c
Add SortDescriptor and SortComparator (#288)
* Port SortDescriptor and SortComparator to FoundationEssentials

rdar://116408260

* Update availability
2023-10-25 10:34:17 -07:00
Tina Liu
31571a4f50
Add String tests from stdlib (#293)
* 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
2023-10-19 09:52:25 -07:00
Tony Parker
d942713680
Sink TimeZone, Locale, Calendar to Essentials (#266)
* Sink Locale, Calendar to Essentials

* Add a Calendar test, make sure that _lock is populated early for NSSwiftCalendar
2023-09-25 16:09:16 -07:00
Jeremy Schonfeld
1f99f94861
Top Level Coder Support for CodableWithConfiguration (#95)
* (107489425) JSON coder support for CodableWithConfiguration

* (107489425) Add availability

* (107489425) Move type constraints to where clause
2023-05-09 15:13:48 -07:00
Jeremy Schonfeld
985f782734
rdar://101354563 (Codable Support for Predicate)
* (101354563) Separate CodableWithConfiguration into standalone file

* (101354563) Update PredicateExpression archive formats

* (101354563) Codable Support for Predicate

* (101354563) Assert on unsupported keypaths
2023-04-26 12:57:40 -07:00
Tony Parker
d1cc2ea0a2
Add some links to known issues to TODOs (#47) 2023-04-18 14:53:06 -07:00
Guillaume Lessard
1c4eacbf54
fix release-mode package build 2023-04-11 16:55:42 -07:00
Guillaume Lessard
9fdb8f2a8b
rename file 2023-04-11 15:45:04 -07:00
Charles Hu
2095f3cf69 rdar://107533913 (Move FormatStyles to FoundationPreview) 2023-04-10 17:18:23 -07:00
Charles Hu
34c45c169c rdar://107156343 (Move JSONEncoder to FoundationPreview) 2023-03-29 09:56:00 -07:00
Jeremy Schonfeld
8ce51672b6
(106775060) Update AttributedString sources for compatibility with FoundationPreview 2023-03-23 13:26:07 -07:00
Charles Hu
e2e38a0bc0 rdar://106051615 (Move Calendar, Locale, and TimeZone to FoundationPreview) 2023-03-03 18:32:33 -08:00
Charles Hu
222a74b687 rdar://105685857 (Move Date to FoundationEssentials) 2023-02-28 14:11:23 -08:00
Charles Hu
c8d6b06cbb rdar://105796506 (Use macOS 9999 instead of Future in availability markings) 2023-02-22 15:17:46 -08:00
Jeremy Schonfeld
fa6e63f2b7
(103142677) Add typealiases to TestSupport, address feedback 2023-02-15 11:02:06 -08:00
Charles Hu
363e0c9a89 FoundationPreview: Initial release 2023-02-07 18:36:16 -08:00