Omniscope Custom Blocks › Preparation/Smart-Date-Parser

Smart Date Parser

Parses text fields holding dates in mixed formats (ISO, day-first or month-first, named months, compact, with time zones) into Date fields, and flags the values it could not read.

Preparation Python

Open the demo in Omniscope Download demo.ioz Sample data: supplier-deliveries.csv Source on GitHub

Omniscope custom block · Preparation

One date field, five formats, two time zones? Real Date fields from every value that holds a date, and a flag on the ones that don't.

Python · pandas, python-dateutil · nothing extra to install

The problem it solves

A buyer combines delivery records from six suppliers. Each supplier's system writes dates its own way: ISO timestamps in UTC, UK day/month dates, named months, compact 250307 codes, local times with a +01:00 offset. Until they are one Date field they can't be sorted, filtered by month or subtracted to get lead times.

This block reads every value on its own and writes a Date field beside the original, with a _failed field marking the values that could not be read.

How it works

What goes in

Supplier deliveries

12 invented deliveries from six suppliers, with an order date and a delivery time in each supplier's own format.

Delivery Supplier Order Date Delivered At
D-101 Hartwell Foods 2025-03-04 2025-03-06T09:30:00Z
D-103 Pennine Packaging 04/03/2025 06/03/2025 11:20
D-105 Calder Print 5 March 2025 7 Mar 2025 16:00
D-106 Calder Print March 12, 2025 2025-03-14 10:15:00+00:00
D-107 Ostler Wholesale 250307 2025-03-10T08:50:00+01:00
D-109 Brightwater Trading 20250319 21-03-2025 13:30
D-110 Brightwater Trading 2025-03-20
D-111 Kestrel Supplies March 2025 2025-03-25 12:00
D-112 Kestrel Supplies 31/02/2025 2025-03-27 12:00

12 rows in the sample file.

The options

Option Demo setting What it does
Fields to parse Order Date, Delivered At The text fields holding dates.
Output suffix _parsed Added to the name of each parsed field; empty replaces the field.
Day first ticked 04/03/2025 is 4 March.
Add failure flag ticked Adds Order Date_parsed_failed and Delivered At_parsed_failed.
Keep original fields ticked The text fields stay beside the parsed ones.
Custom formats %y%m%d Reads Ostler Wholesale's 250307 as 7 March 2025.

What comes out

Parsed deliveries (selected records)

Delivery Order Date Order Date_parsed Order Date_parsed_failed Delivered At_parsed
D-101 2025-03-04 2025-03-04 false 2025-03-06 09:30
D-103 04/03/2025 2025-03-04 false 2025-03-06 11:20
D-105 5 March 2025 2025-03-05 false 2025-03-07 16:00
D-107 250307 2025-03-07 false 2025-03-10 07:50
D-109 20250319 2025-03-19 false 2025-03-21 13:30
D-110 2025-03-20 2025-03-20 false
D-111 March 2025 true 2025-03-25 12:00
D-112 31/02/2025 true 2025-03-27 12:00

12 records, 8 fields. Without the custom format, 250307 would be read as 25 March 2007; D-107's delivery at 08:50 +01:00 is 07:50 UTC.

Where it pays off

Purchasing: Supplier and carrier feeds

Combine delivery, invoice and shipping dates from several suppliers' exports and compute lead times on one Date field.

Finance: Bank and card statements

Statement exports from different banks write dates differently; parse them into one field before reconciling.

Data migration: Legacy systems

Old systems and hand-kept spreadsheets mix formats within one column; the _failed flag gives the list of values to correct by hand.

Web and event data: Timestamps with offsets

Event logs with Z and +01:00 timestamps come out in UTC, so events from different sources sort in the right order.

Use cases describe typical scenarios and are illustrative; the sample data is invented.

Why do this in Omniscope

How it fits into an Omniscope workflow

Supplier files (Append files) → Smart Date Parser → Record filter (_failed true, to a review table) → Field organiser (lead time in days) → Report

Put it straight after the source, before anything that groups or filters by date.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder): 12 deliveries from six suppliers.
  2. The question: how many days did each delivery take from order?
  3. Open Smart Date Parser: fields Order Date and Delivered At, Day first ticked, custom format %y%m%d. Run it.
  4. Look at the output: every order date is 4 to 20 March 2025 except D-111 and D-112, which are flagged.
  5. Clear Custom formats and run again: D-107 and D-108 now show 2007 and 2014. Untick Day first: D-103 becomes 3 April, while D-101 (2025-03-04) stays 4 March.

Running in Omniscope

Omniscope workflow
Omniscope workflow

The demo project's workflow: the sample data, the block, and a Validate data check on its output.

Language and libraries

Python. It uses pandas and python-dateutil.

Both are part of Omniscope's Python environment. It needs nothing else installed.

Tested

The block is covered by automated tests that run its script against a stand-in for Omniscope's Python API: the sample data, ISO dates with Day first ticked, month-first dates, mixed time zones, incomplete dates, custom formats tried first, the option defaults, in-place parsing and dropped originals, number and Date fields, empty input, bad options, and 100,000 values.

Reference

Fields it reads

NameTypeWhat it does
Fields to parseFieldsText fields holding dates. Fields that are already Date fields are copied unchanged.

Options

NameTypeWhat it does
Output suffixTextAdded to each field name for the parsed field (Order Date becomes Order Date_parsed). Leave empty to replace the field in place.
Day firstYes / noRead ambiguous dates such as 04/03/2025 as day/month (4 March). Unticked, they are read month/day (3 April). Dates starting with a four-digit year are always year-month-day.
Add failure flagYes / noAdd a field ending in _failed that is true where a value was present but could not be read.
Keep original fieldsYes / noKeep the original text fields next to the parsed ones. Only applies when there is an output suffix.
Custom formatsTextOptional. Python strptime codes, comma-separated, tried before the built-in formats; for example %y%m%d,%d.%m.%Y

Outputs

OutputWhat it holds
ParsedThe input with a Date field (and a _failed flag) for each parsed field.