hledger-lib
Safe HaskellNone
LanguageGHC2021

Hledger.Read.LatestDates

Description

The .latest mechanism: a per-input-file record of the latest transaction date(s) seen on the previous read, used by hledger import (and any reader called with new_=True) to filter out already-seen transactions.

For an input file F, the latest dates are kept in a .latest.F hidden file in F's directory. They are written after a successful import and read on the next one. The CSV rules reader's archive rule also consults these to decide whether a fresh archive is warranted.

These helpers live in their own module so both the high-level reader (Read) and the low-level CSV rules reader (RulesReader) can use them without a module-graph cycle.

Synopsis

Documentation

type LatestDates = [Day] Source #

One or more dates of the same kind, eg the latest transaction date(s) read from a file.

data LatestDatesForFile Source #

The path of an input file, and its current LatestDates.

Constructors

LatestDatesForFile FilePath LatestDates 

Instances

Instances details
Show LatestDatesForFile Source # 
Instance details

Defined in Hledger.Read.LatestDates

Methods

showsPrec :: Int -> LatestDatesForFile -> ShowS

show :: LatestDatesForFile -> String

showList :: [LatestDatesForFile] -> ShowS

latestDates :: [Day] -> LatestDates Source #

Get all instances of the latest date in an unsorted list of dates. Ie, if the latest date appears once, return it in a one-element list, if it appears three times (anywhere), return three of it.

latestDatesFileFor :: FilePath -> FilePath Source #

Where to save latest transaction dates for the given file path: .latest.FILE in FILE's directory.

previousLatestDates :: FilePath -> IO LatestDates Source #

What were the latest transaction dates seen the last time this journal file was read ? If there were multiple transactions on the latest date, that number of dates is returned, otherwise just one. Or none if no transactions were read, or if latest dates info is not available for this file.

saveLatestDates :: LatestDates -> FilePath -> IO () Source #

Save the given latest date(s) seen in the given data FILE, in a hidden file named .latest.FILE, creating it if needed. Unless no latest dates are provided, in which case do nothing.

saveLatestDatesForFiles :: [LatestDatesForFile] -> IO () Source #

Save each file's latest dates.

journalFilterSinceLatestDates :: LatestDates -> Journal -> (Journal, LatestDates) Source #

Given zero or more latest dates (all the same, representing the latest previously seen transaction date, and how many transactions were seen on that date), remove transactions with earlier dates from the journal, and the same number of transactions on the latest date, if any, leaving only transactions that we can assume are newer. Also returns the new latest dates of the new journal.