Skip to content

Instantly share code, notes, and snippets.

@kspurgin
Created June 20, 2019 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kspurgin/b5e87e02fc33ee9c18da50e67fe2a3b7 to your computer and use it in GitHub Desktop.
Save kspurgin/b5e87e02fc33ee9c18da50e67fe2a3b7 to your computer and use it in GitHub Desktop.
**Default 'usable date' range is 500 to current year + 6**
MarcToArgot
MarcToArgot::Macros::Shared::PublicationYear
usable_date? - determine whether a given date value is usable for deriving a reasonable single value for sorting/filtering
1997 is usable - 4 digits, in usable range
688 is usable - fewer than 4 digits, but in usable range
9999 is usable - gets translated into current year + 1
499 is NOT usable - out of usable range
6754 is NOT usable - 4 digits, but out of usable range
1uuu is NOT usable - indicates only the millennium
uuuu is NOT usable - unknown date
is_range? - determine whether a single date value from fixed field should be interpreted as a range
1997 is not a range: 4 digit date
199u is a range: decade
19uu is a range: century
uuuu is not a range: unknown
198| is not a range: 3 digit date
66u| is a range: 3 digit date, decade known
is_range? - determine whether a single date value from variable field should be interpreted as a range
1997 is not a range: 4 digit date
199- is a decade range
19-- is a century range
1--- is a millennium range
198? is not a range: it is a best guess at the specific date
get_date - translate a fixed field date into a single value for further processing if it is usable, and discard it completely from further processing if it is unusable
19uu returns 1949 -- midpoint of range 1900-1999
688 returns 688 -- no translation necessary
9876 returns nil -- not a usable date for further processing
get_date - translate a variable field date into a single value for further processing if it is usable, and discard it completely from further processing if it is unusable
WHEN 008/06 is not c, d, or u
197- returns 1974 -- midpoint of range 1970-1979
688 returns 688 -- no translation necessary
9876 returns nil -- not a useful date for further processing
c1999 returns 1999 -- extract only digits, followed by -
-2018 returns 2018 -- extracts only digits, followed by -
192-- (extra hyphen) returns 1924 -- extra hyphen ignored when figuring midpoint of range
[197-?] returns 1974 -- ignores brackets and terminal question mark
[2017];©2018 returns 2017 -- takes only the first date
[between 1950 and 1959?] returns 1950 -- takes only the first date
'-December 16, 2014.' returns 2014 -- takes only the year
[n.d.] returns nil -- no recognized year pattern found
WHEN 008/06 is c, d, or u
192-- (extra hyphen indicating open date range) returns 1924 -- extra hyphen ignored when figuring midpoint of range
[2017];©2018 returns 2018 -- takes only the final year date
midpoint_or_usable - called when it looks like there is a range. Given the two dates derived using the get_date logic, tries to return the logical midpoint or otherwise usable value from the range
1850, 9999: returns 1850, use date1 if date2=9999
1850, 1900: returns 1875, the midpoint between dates since date1 < date2
2000, 1984: returns 2000, since date1 > date2 (which is not a reasonable range!)
1894, 1894: returns 1894, sincd date1 = date2 (which is not a range)
1894, nil: returns 1894, the only usable date given
nil, 2019: returns 2019, the only usable date given
LOGIC BASED ON DATE TYPE AND OTHER FACTORS (\ indicates a blank character)
WHEN DateType = b (No dates given; B.C. date involved)
AND no 260 or 264 having dates
(MTA) pub date not set
AND record has 260 with |cp1999
(MTA) pub date = 1999
AND record has 264\0 with |c1999, followed by 264\1 with |c2000
(MTA) pub date = 2000 (uses date from preferred 260 or 264)
WHEN DateType = c (Continuing resource currently published)
AND date2=9999
(MTA) pub date = current year+1 (use translated date2 if it is a usable date)
AND date2=2018
(MTA) pub date = 2018 (use translated date2 if it is a usable date)
AND date2=2uuu
AND no 260/264 date present
(MTA) pub date = nil (millennium range not usable, will not set pub date from date1 since that would poorly represent the currency of a currently published continuing resource)
AND 260/264 date = |c1900-200-
(MTA) pub date = nil (millennium range not usable, will not set pub date from date1 since that would poorly represent the currency of a currently published continuing resource; gets last date from 26X and treats as range)
WHEN DateType = d (Continuing resource ceased publication)
AND dates = \\\\1949
(MTA) pub date = 1949 (date2 if present and usable, to represent the most current material that was published, since there is no start date)
AND dates = 194519uu
(MTA) pub date = 1972 (assuming pub cannot cease before beginning, midpoint of date2 treated as 1945-1999)
AND dates = 1945\\\\
AND no 260/264 date present
(MTA) pub date = nil (will not set pub date from date1 because it would poorly represent the ultimate currency of a later-ceased continuing resource)
AND 260 with |c1945-1984. present
(MTA) pub date = 1984 (will not set pub date from date1 because it would poorly represent the ultimate currency of a later-ceased continuing resource; takes last year recorded in 26X)
AND dates = 19459999
(MTA) pub year = current year (assume record marked ceased without adding ceased date in error, and that such an error would be caught somewhat soon)
WHEN DateType = e (Detailed date)
AND dates = 20120215
(MTA) pub date = 2012 (usable date1)
AND dates = 02120215 (date1 typo for 2012)
AND 260 with |c2/15/2012 present
(MTA) pub date = 2012 (date1 unusable, cannot set year from date2, take year from first 260/264
AND no 260/264 date present
(MTA) pub date = nil (date1 unusable, cannot set year from date2)
WHEN DateType = i (Inclusive dates of collection)
AND dates = 19101950
(MTA) pub date = 1910 (use date1)
AND dates = 1uuu1950
AND no 260/264 date present
(MTA) pub date = nil (do not set date from date2)
AND 260/264 has |c1910 to 1950
(MTA) pub date = 1910 (do not set date from date2; get first date from 26X field)
WHEN DateType = k (Range of years of bulk of collection)
(MTA) works the same way as DateType = i (set only from date1 or first 26X date)
WHEN DateType = m (Multiple dates)
AND dates = 19662000
(MTA) pub date = 2000 (prefer date2 if it is a usable, non-9999 date
AND dates = 19669999
(MTA) pub date = 1966 (use date1 if date2 = 9999)
AND dates = 198u9999
(MTA) pub date = 1984 (use date1, treating as range if necessary, if date2 is unusable
AND dates = \\\\9999
AND no 260/4 date present
(MTA) pub date = nil (no usable dates -- 9999 not considered usable for this date type)
AND 260/264 has |c1910, 1950
(MTA) pub date = 1950 (get final date from best 26X field)
WHEN DateType = n (Dates unknown)
AND dates = 18501900
(MTA) pub date = 1875 (use midpoint between the two usable dates)
AND dates = n19661966
(MTA) pub date = 1966 (use date1 if date2 = date1)
AND dates = n20001950
(MTA) pub date = 2000 (use date1 if date2 > date1)
AND dates = n19842uuu
(MTA) pub date = 1984 (use date1 if date2 unusable)
AND dates = n1uuu2018
(MTA) pub date = 2018 (use date2 if date1 unusable)
AND dates = n1uuu2uuu
AND no 260/4 dates present
(MTA) pub date = nil (no usable dates)
AND 260/264 has |c1910, 1950
(MTA) pub date = 1910 (get initial date from best 26X field)
WHEN DateType = p (Date of distribution/release/issue and production/recording session when different)
(MTA) works the same as DateType = m (preferences date2)
WHEN DateType = q (Questionable date)
(MTA) works the same as DateType = n
WHEN DateType = r (Reprint/reissue date and original date)
(MTA) works the same as DateType = m (preferences date2)
WHEN DateType = s (Single known date/probable date)
(MTA) works the same way as DateType = i (set only from date1 or first 26X date)
WHEN DateType = t (Publication date and copyright date)
(MTA) works the same way as DateType = i (set only from date1 or first 26X date)
WHEN DateType = u (Continuing resource status unknown)
AND dates = 20129999
(MTA) pub date = current year + 1 (9999 used in its translated form)
AND dates = 19002uuu
(MTA) pub date = 1900 (use date1 if no usable date2)
AND dates = 1uuu2uuu
AND 260/4 has |c1989 through 2017.
(MTA) pub date = 2017 (use final 260/4 date if no useable 008 date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment