You can contribute for a given year up until your federal tax filing deadline the following spring, usually April 15.
Filing extensions do not extend it. Even if you get an extension to file your return, the contribution deadline stays the same.
If you deposit money between January 1 and the deadline, tell your custodian which year it counts toward. Otherwise, it may be applied to the current year instead of the prior one.