Hi All
@Samuel_Langford raised a question about some new date formulas elsewhere in the community. Coda makes it EXTREMELY easy to create a pack so I thought I would give it a go.
Samuel wanted to check three things,
- Whether one date is before another
- Whether one date is after another
- Whether a third date falls between two other dates.
Due to my lack of experience, it probably took me two hours to get this done. I also made use of the following JavaScript reference.
Whether it is the best or the worst out there I don’t know, but, it helped me get the job done.
So if you have been considering making a pack but thought it would be too difficult, I share the code for the “More Formulas” pack below. Like everything in Coda, it is easy to get into, and the possibilities are endless.
If you feel like doing some digital gardening in that pack, please let me know and I will give yoju access.
Happy Packing
Piet
import * as coda from "@codahq/packs-sdk";
// This line creates your new Pack.
export const pack = coda.newPack();
// Here, we add a new formula to this Pack.
pack.addFormula({
// This is the name that will be called in the formula builder.
// Remember, your formula name cannot have spaces in it.
name: "isBeforeDate",
description: "Checks whether Date1 is before Date2",
// If your formula requires one or more inputs, you’ll define them here.
// Here, we're creating a string input called “name”.
parameters: [
coda.makeParameter({
type: coda.ParameterType.Date,
name: "Date1",
description: "The first date in the comparison",
}),
coda.makeParameter({
type: coda.ParameterType.Date,
name: "Date2",
description: "The second date in the comparison",
}),
],
// The resultType defines what will be returned in your Coda doc. Here, we're
// returning a simple text string.
resultType: coda.ValueType.Boolean,
// Everything inside this execute statement will happen anytime your Coda
// formula is called in a doc. An array of all user inputs is always the 1st
// parameter.
execute: async function ([date1,date2]) {
if (date1 < date2)
return true;
if (date1 >= date2)
return false;
},
});
// Here, we add a second formula to this Pack.
pack.addFormula({
// This is the name that will be called in the formula builder.
// Remember, your formula name cannot have spaces in it.
name: "isAfterDate",
description: "Checks whether Date1 is after Date2",
// If your formula requires one or more inputs, you’ll define them here.
// Here, we're creating a string input called “name”.
parameters: [
coda.makeParameter({
type: coda.ParameterType.Date,
name: "Date1",
description: "The first date in the comparison",
}),
coda.makeParameter({
type: coda.ParameterType.Date,
name: "Date2",
description: "The second date in the comparison",
}),
],
// The resultType defines what will be returned in your Coda doc. Here, we're
// returning a simple text string.
resultType: coda.ValueType.Boolean,
// Everything inside this execute statement will happen anytime your Coda
// formula is called in a doc. An array of all user inputs is always the 1st
// parameter.
execute: async function ([date1,date2]) {
if (date1 > date2)
return true;
if (date1 <= date2)
return false;
},
});
pack.addFormula({
// This is the name that will be called in the formula builder.
// Remember, your formula name cannot have spaces in it.
name: "isBetweenDates",
description: "Checks whether Date3 is between Date1 and Date2",
// If your formula requires one or more inputs, you’ll define them here.
// Here, we're creating a string input called “name”.
parameters: [
coda.makeParameter({
type: coda.ParameterType.Date,
name: "Date1",
description: "The first date in the comparison",
}),
coda.makeParameter({
type: coda.ParameterType.Date,
name: "Date2",
description: "The second date in the comparison",
}),
coda.makeParameter({
type: coda.ParameterType.Date,
name: "Date3",
description: "The third date in the comparison",
}),
],
// The resultType defines what will be returned in your Coda doc. Here, we're
// returning a simple text string.
resultType: coda.ValueType.Boolean,
// Everything inside this execute statement will happen anytime your Coda
// formula is called in a doc. An array of all user inputs is always the 1st
// parameter.
execute: async function ([date1,date2,date3]) {
if (date3 > date2)
return false
if (date3 < date1)
return false
return true
},
});```