def METHOD_NAME(self, ptype):
    def _creation_time(field, data):
        if data.ds.cosmological_simulation:
            a_form = data[(ptype, "StellarFormationTime")]
            z_form = 1 / a_form - 1
            creation_time = data.ds.cosmology.t_from_z(z_form)
        else:
            t_form = data[(ptype, "StellarFormationTime")]
            creation_time = data.ds.arr(t_form, "code_time")
        return creation_time
    self.add_field(
        (ptype, "creation_time"),
        sampling_type="particle",
        function=_creation_time,
        units=self.ds.unit_system["time"],
    )
    def _age(field, data):
        return data.ds.current_time - data[(ptype, "creation_time")]
    self.add_field(
        (ptype, "age"),
        sampling_type="particle",
        function=_age,
        units=self.ds.unit_system["time"],
    )