date-fns#isWithinInterval JavaScript Examples
The following examples show how to use
date-fns#isWithinInterval.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.js From lnft with GNU Affero General Public License v3.0 | 7 votes |
canAccept = ({ type, artwork, created_at, accepted }, debug) => {
let $user = get(user);
if (accepted) return false;
let isOwner = ({ owner }) => $user && $user.id === owner.id;
let underway = ({ auction_start: s, auction_end: e }) =>
e && isWithinInterval(new Date(), { start: parseISO(s), end: parseISO(e) });
return (
artwork &&
isCurrent(artwork, created_at, type) &&
isOwner(artwork) &&
!underway(artwork)
);
}
Example #2
Source File: utils.js From lnft with GNU Affero General Public License v3.0 | 6 votes |
underway = ({ auction_start: s, auction_end: e }) =>
e && isWithinInterval(new Date(), { start: parseISO(s), end: parseISO(e) })
Example #3
Source File: timeline-intervals.js From discovery-mobile-ui with MIT License | 6 votes |
generateNextIntervalFunc = (intervalMap, intervalCount) => {
const intervalIterator = createIntervalIterator(intervalMap, intervalCount);
let currentInterval = intervalIterator.next().value;
return (date) => {
while (!isWithinInterval(date, currentInterval.interval)) {
const { done, value } = intervalIterator.next();
if (done) {
return null;
}
currentInterval = value;
}
return currentInterval;
};
}
Example #4
Source File: index.js From discovery-mobile-ui with MIT License | 5 votes |
allRecordsWithFilterResponseSelector = createSelector(
[
allValidRecordsSortedByDateSelector,
activeCollectionSelector,
dateRangeForAllRecordsSelector,
activeCollectionDateRangeFilterSelector,
],
(items, activeCollection, dateRangeForAllRecords, activeCollectionDateRangeFilter) => {
const { minimumDate, maximumDate } = dateRangeForAllRecords;
const {
resourceTypeFilters,
showCollectionOnly,
showMarkedOnly,
records,
} = activeCollection;
// eslint-disable-next-line max-len
const { dateRangeStart = minimumDate, dateRangeEnd = maximumDate } = activeCollectionDateRangeFilter;
return items.map(({
id, type, subType, timelineDate,
}) => ({
id,
type,
subType,
timelineDate,
passesFilters: {
type: resourceTypeFilters[type],
date: dateRangeStart && dateRangeEnd && isWithinInterval(
timelineDate,
{
start: dateRangeStart,
end: dateRangeEnd,
},
),
inCollection: records[id]?.saved,
dateSaved: records[id]?.dateSaved,
showCollectionOnly: !showCollectionOnly || (showCollectionOnly && records[id]?.saved),
isHighlighted: records[id]?.highlight,
showHighlightedOnly: !showMarkedOnly || (showMarkedOnly && records[id]?.highlight),
},
}));
},
)
Example #5
Source File: signing.js From lnft with GNU Affero General Public License v3.0 | 4 votes |
check = async (psbt) => {
const [txid, inputs, outputs] = await parse(psbt);
const multisig = (
await hasura.post({ query: allMultisig }).json().catch(console.log)
).data.users.map((u) => u.multisig);
let variables = { assets: outputs.map((o) => o.asset) };
let {
data: { artworks },
} = await hasura.post({ query, variables }).json();
artworks.map(
({
asset,
has_royalty,
royalty_recipients,
artist,
owner,
list_price,
asking_asset,
auction_start,
auction_end,
}) => {
let outs = outputs.filter((o) => o.asset === asking_asset);
let toRoyaltyRecipients = outs
.filter((o) => {
const recipientsWithOuts = royalty_recipients.find((recipient) => {
let unconfidential;
try {
unconfidential = Address.fromConfidential(
recipient.address
).unconfidentialAddress;
} catch (e) {}
return (
recipient.address === o.address || unconfidential === o.address
);
});
return !!recipientsWithOuts;
})
.reduce((a, b) => (a += b.value), 0);
let toOwner =
outs
.filter(
(o) => o.address === owner.address || o.address === owner.multisig
)
.reduce((a, b) => a + parseInt(b.value), 0) -
inputs
.filter(
(o) =>
o.asset === asking_asset &&
(o.address === owner.address || o.address === owner.multisig)
)
.reduce((a, b) => a + parseInt(b.value), 0);
if (auction_end) {
let start = parseISO(auction_start);
let end = parseISO(auction_end);
if (
toOwner !== list_price &&
isWithinInterval(new Date(), { start, end })
)
throw new Error("Auction underway");
}
if (has_royalty) {
if (toOwner) {
let amountDue = 0;
for (let i = 0; i < royalty_recipients.length; i++) {
const element = royalty_recipients[i];
amountDue += Math.round((toOwner * element.amount) / 100);
}
if (toRoyaltyRecipients < amountDue && artist.id !== owner.id)
throw new Error("Royalty not paid");
}
if (
outputs.find(
(o) => o.asset === asset && !multisig.includes(o.address)
)
) {
throw new Error(
"Token cannot be transferred to an external address when royalties are activated or auction is underway."
);
}
}
}
);
}