Locale-Proof Evaluate and Format
Your extension exchanges documents with an external REST service. On your machine every payload was perfect; then the first Danish customer went live and the service started rejecting documents — amounts arrived as 1.234,56 and dates as 05-02-2026. Nothing in the code had changed: Format and Evaluate quietly follow the regional settings of the session they run in, and the customer's server doesn't speak your locale.
Your job is a conversion codeunit that writes and reads the same wire text on every server, whatever its regional settings.
Requirements
Create a codeunit named "Wire Format" with four public procedures:
procedure ToWireDecimal(Value: Decimal): Text
procedure ToWireDate(Value: Date): Text
procedure FromWireDecimal(WireText: Text; var Value: Decimal): Boolean
procedure FromWireDate(WireText: Text; var Value: Date): BooleanRules:
ToWireDecimalrenders the value as culture-invariant wire text: a leading-for negative values, plain digits, and a dot.before any fractional part — never a group (thousand) separator, never a comma.1234567.89must come out as1234567.89and-1234.5as-1234.5.ToWireDaterenders the date asYYYY-MM-DDwith zero-padded month and day: 3 February 2026 must come out as2026-02-03. Only real (non-zero) dates are graded.FromWireDecimalparses wire decimal text intoValueand returnstrue. Text that is not in wire format returnsfalse— that includes locale-formatted text such as1,5(a comma is never valid on the wire) as well as outright garbage. It must never raise an error, whatever the text contains.FromWireDatedoes the same forYYYY-MM-DDdates:2026-01-23parses to 23 January 2026; text in any other shape returnsfalsewithout raising an error.- Round trip: any text
ToWireDecimalorToWireDateproduces must be accepted by the matchingFromWireprocedure and yield exactly the original value. - After a failed parse, the returned
falseis the only graded signal — whatever is left in thevarparameter is not checked.
What the tests check
The ToWire procedures are compared against exact strings — note the dot, the leading minus and the zero padding. The FromWire procedures are fed valid wire text (which must parse to the exact value), locale-formatted text — comma decimals like 1,5 and day-first dates like 05-02-2026 (each must return false — not true, and not an error) — and garbage (which must return false). Two round-trip tests run on generated values, so hardcoding the examples won't pass.