Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By my eye, it appears that all dates are first converted to Unix timestamps:
// Work from a timestamp
$from = MigrationBase::timestamp($from);
if ($to) {
$to = MigrationBase::timestamp($to);
}
Timestamps will not work for dates prior to the Unix epoch. We should be using DateTime, and use Date module's helper functions for converting between the different formats. It'd probably be helpful to get Karen Stevenson's thoughts around this, too.
Comments
Comment #1
q0rban CreditAttribution: q0rban commentedHmm, maybe I'm wrong about this. I guess strtotime returns negative numbers for times prior to the epoch? Still, Karen always advises me not to use timestamps, and when Karen says something about dates, I listen. ;)
Comment #2
mikeryan@q0rban: Date migration support is in the Date module itself now.
Comment #3
KarenS CreditAttribution: KarenS commentedI'm going to switch this to a task. Timestamps are more limited but will work fine so long as you are not trying to migrate historical dates, so it is probably not critical to fix immediately.
Comment #4
hamish_s CreditAttribution: hamish_s commentedSo, as I read through as many of the issue reports (on dates before 1901) as I possibly can, may I now conclude that dates before 1901 cannot be imported? That is, as KarenS suggests, that for those who need to import historical dates (as I do), we are a small group of users, and therefore, given the resource requirements, it is unlikely to get fixed in any reasonable time??
I need my dates to be in ISO format for use by another module, and so, am I SOL? We will have to load manually?
Thanks,
H
Comment #5
sharonknieper CreditAttribution: sharonknieper commentedhamish_s I'm working on a work around for my historical dates by writing a callback in the field mapping. If the value looks like a timestamp already MigrationBase::timestamp passes it along without processing with strtotime, so if you get the correct timestamp first I think it should be okay. This is what I did:
and
I've only started testing so I'm not sure how well this will work, but I thought I'd share the idea of a callback.
Comment #6
sharonknieper CreditAttribution: sharonknieper commentedhamish_s realized you mentioned pre 1901 dates. In my testing it looks like the following adjustment to the above code would work:
replace
with