widget news fetch

This commit is contained in:
Alma 2025-04-13 22:11:46 +02:00
parent ba911216ef
commit 971131fd47
1375 changed files with 16589 additions and 2380 deletions

5
.env
View File

@ -46,3 +46,8 @@ ROCKET_CHAT_TOKEN=w91TYgkH-Z67Oz72usYdkW5TZLLRwnre7qyAhp7aHJB
ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB
LEANTIME_TOKEN=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb
LEANTIME_API_URL=https://agilite.slm-lab.net
DB_USER=alma
DB_PASSWORD=Sict33711###
DB_NAME=rivacube
DB_HOST=@https://cube.governance-labs.com

69
app/api/news/route.ts Normal file
View File

@ -0,0 +1,69 @@
import { NextResponse } from 'next/server';
import { Pool } from 'pg';
// Create a new pool using the environment variables
const pool = new Pool({
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
host: process.env.DB_HOST?.replace('@https://', ''),
database: process.env.DB_NAME,
ssl: {
rejectUnauthorized: false // Required for some cloud databases
}
});
export async function GET() {
try {
// Connect to the database
const client = await pool.connect();
try {
// Query the news table for the latest 10 news items
const result = await client.query(`
SELECT
id,
title,
url,
date,
source,
description,
category,
sentiment_score,
sentiment,
symbols,
symbol
FROM news
ORDER BY date DESC
LIMIT 10
`);
// Format the response
const news = result.rows.map(row => ({
id: row.id,
title: row.title,
url: row.url,
date: row.date,
source: row.source,
description: row.description,
category: row.category,
sentiment: {
score: row.sentiment_score,
label: row.sentiment
},
symbols: row.symbols,
symbol: row.symbol
}));
return NextResponse.json({ news });
} finally {
// Release the client back to the pool
client.release();
}
} catch (error) {
console.error('Database connection error:', error);
return NextResponse.json(
{ error: 'Failed to fetch news' },
{ status: 500 }
);
}
}

View File

@ -2,15 +2,26 @@
import { useEffect, useState } from "react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { RefreshCw } from "lucide-react";
import { useSession } from "next-auth/react";
import { formatDistanceToNow } from 'date-fns';
import { fr } from 'date-fns/locale';
import Link from 'next/link';
import { Button } from '@/components/ui/button';
import { RefreshCw } from 'lucide-react';
interface NewsItem {
id: string;
id: number;
title: string;
url: string;
date: string;
source: string;
description: string;
category: string;
sentiment: {
score: number | null;
label: string | null;
};
symbols: string[] | null;
symbol: string | null;
}
export function News() {
@ -18,26 +29,30 @@ export function News() {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [refreshing, setRefreshing] = useState(false);
const { status } = useSession();
const [dbStatus, setDbStatus] = useState<'connecting' | 'connected' | 'error'>('connecting');
const fetchNews = async (isRefresh = false) => {
if (isRefresh) setRefreshing(true);
setLoading(true);
// Placeholder data - replace with actual API call
const mockNews = [
{ id: '1', title: 'New Project Management Features Released', date: '2024-03-20', category: 'Product Update' },
{ id: '2', title: 'Team Meeting Schedule Changes', date: '2024-03-19', category: 'Announcement' },
{ id: '3', title: 'Upcoming Training Sessions', date: '2024-03-18', category: 'Training' },
];
setDbStatus('connecting');
try {
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 1000));
setNews(mockNews);
const response = await fetch('/api/news');
if (!response.ok) {
throw new Error('Failed to fetch news');
}
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
setNews(data.news);
setError(null);
setDbStatus('connected');
} catch (err) {
setError('Failed to fetch news');
setError('Failed to load news. Please try again later.');
setDbStatus('error');
console.error('Error fetching news:', err);
} finally {
setLoading(false);
@ -46,63 +61,124 @@ export function News() {
};
useEffect(() => {
if (status === 'authenticated') {
fetchNews();
}
}, [status]);
fetchNews();
}, []);
if (status === 'loading' || loading) {
if (loading && !refreshing) {
return (
<Card className="transition-transform duration-500 ease-in-out transform hover:scale-105 bg-white/95 backdrop-blur-sm border-0 shadow-lg h-full">
<CardHeader className="flex flex-row items-center justify-between pb-2 border-b border-gray-100">
<CardTitle className="text-lg font-semibold text-gray-800">News</CardTitle>
<Card className="w-full">
<CardHeader>
<CardTitle>News</CardTitle>
</CardHeader>
<CardContent className="p-6">
<p className="text-center text-gray-500">Loading...</p>
<CardContent>
<div className="flex flex-col items-center justify-center h-32 space-y-2">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"></div>
<p className="text-sm text-gray-500">
{dbStatus === 'connecting' ? 'Connecting to database...' : 'Loading news...'}
</p>
</div>
</CardContent>
</Card>
);
}
if (error) {
return (
<Card className="w-full">
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle>News</CardTitle>
<Button
variant="ghost"
size="icon"
onClick={() => fetchNews(true)}
disabled={refreshing}
className={`${refreshing ? 'animate-spin' : ''}`}
>
<RefreshCw className="h-4 w-4" />
</Button>
</CardHeader>
<CardContent>
<div className="text-red-500 space-y-2">
<p>{error}</p>
<p className="text-sm text-gray-500">
{dbStatus === 'error' ? 'Database connection error' : 'Failed to fetch news'}
</p>
</div>
</CardContent>
</Card>
);
}
return (
<Card className="transition-transform duration-500 ease-in-out transform hover:scale-105 bg-white/95 backdrop-blur-sm border-0 shadow-lg h-full">
<CardHeader className="flex flex-row items-center justify-between pb-2 space-x-4 border-b border-gray-100">
<CardTitle className="text-lg font-semibold text-gray-800">News</CardTitle>
<Card className="w-full">
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle>News</CardTitle>
<Button
variant="ghost"
size="icon"
onClick={() => fetchNews(true)}
disabled={refreshing}
className={`${refreshing ? 'animate-spin' : ''} text-gray-600 hover:text-gray-900`}
className={`${refreshing ? 'animate-spin' : ''}`}
>
<RefreshCw className="h-4 w-4" />
</Button>
</CardHeader>
<CardContent className="p-3">
{error ? (
<p className="text-center text-red-500">{error}</p>
) : (
<div className="space-y-2 max-h-[220px] overflow-y-auto">
{news.length === 0 ? (
<p className="text-center text-gray-500">No news available</p>
) : (
news.map((item) => (
<div
key={item.id}
className="p-2 hover:bg-gray-50/50 rounded-lg transition-colors"
>
<div className="flex items-center justify-between mb-1">
<span className="text-sm text-gray-500">{item.date}</span>
<span className="text-xs px-2 py-0.5 rounded-full bg-blue-50 text-blue-600">
{item.category}
</span>
<CardContent>
<div className="space-y-4">
{news.length === 0 ? (
<div className="text-center text-gray-500 py-8">
No news available
</div>
) : (
news.map((item) => (
<div key={item.id} className="border-b pb-4 last:border-b-0">
<div className="flex items-start justify-between">
<div className="flex-1">
<Link
href={item.url}
target="_blank"
rel="noopener noreferrer"
className="text-blue-600 hover:underline font-medium"
>
{item.title}
</Link>
<p className="text-sm text-gray-500 mt-1">
{item.source} {formatDistanceToNow(new Date(item.date), { addSuffix: true, locale: fr })}
</p>
{item.description && (
<p className="text-sm text-gray-600 mt-2 line-clamp-2">
{item.description.replace(/<[^>]*>/g, '')}
</p>
)}
</div>
<h3 className="text-sm font-medium text-gray-800 line-clamp-2">{item.title}</h3>
{item.sentiment.score !== null && (
<div className={`ml-4 px-2 py-1 rounded text-sm ${
item.sentiment.score > 0 ? 'bg-green-100 text-green-800' :
item.sentiment.score < 0 ? 'bg-red-100 text-red-800' :
'bg-gray-100 text-gray-800'
}`}>
{item.sentiment.label || 'Neutral'}
</div>
)}
</div>
))
)}
</div>
)}
{(item.symbols?.length || item.symbol) && (
<div className="mt-2 flex flex-wrap gap-2">
{item.symbols?.map((symbol, index) => (
<span key={index} className="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">
{symbol}
</span>
))}
{item.symbol && !item.symbols?.includes(item.symbol) && (
<span className="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">
{item.symbol}
</span>
)}
</div>
)}
</div>
))
)}
</div>
</CardContent>
</Card>
);

255
node_modules/.package-lock.json generated vendored
View File

@ -2185,11 +2185,21 @@
"version": "22.10.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.5.tgz",
"integrity": "sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ==",
"dev": true,
"dependencies": {
"undici-types": "~6.20.0"
}
},
"node_modules/@types/pg": {
"version": "8.11.12",
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.11.12.tgz",
"integrity": "sha512-D8qPxnq0rgpvZPYwMxAZffxvlk2mtgimLC5kos8uM7+3wPKfTESxtpD49cfB5w1UnodZL7oYnjFHT5+cB3Gw9Q==",
"license": "MIT",
"dependencies": {
"@types/node": "*",
"pg-protocol": "*",
"pg-types": "^4.0.1"
}
},
"node_modules/@types/prop-types": {
"version": "15.7.14",
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.14.tgz",
@ -2215,16 +2225,6 @@
"date-fns": "^3.3.1"
}
},
"node_modules/@types/react-datepicker/node_modules/date-fns": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz",
"integrity": "sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==",
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/kossnocorp"
}
},
"node_modules/@types/react-dom": {
"version": "18.3.5",
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.5.tgz",
@ -2675,9 +2675,9 @@
}
},
"node_modules/date-fns": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.0.0.tgz",
"integrity": "sha512-xjDz3rNN9jp+Lh3P/4MeY4E5HkaRnEnrJCcrdRZnKdn42gJlIe6hwrrwVXePRwVR2kh1UcMnz00erYBnHF8PFA==",
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz",
"integrity": "sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==",
"license": "MIT",
"funding": {
"type": "github",
@ -3407,6 +3407,12 @@
"node": ">= 6"
}
},
"node_modules/obuf": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz",
"integrity": "sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==",
"license": "MIT"
},
"node_modules/oidc-token-hash": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.3.tgz",
@ -3485,6 +3491,161 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/pg": {
"version": "8.14.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.14.1.tgz",
"integrity": "sha512-0TdbqfjwIun9Fm/r89oB7RFQ0bLgduAhiIqIXOsyKoiC/L54DbuAAzIEN/9Op0f1Po9X7iCPXGoa/Ah+2aI8Xw==",
"license": "MIT",
"dependencies": {
"pg-connection-string": "^2.7.0",
"pg-pool": "^3.8.0",
"pg-protocol": "^1.8.0",
"pg-types": "^2.1.0",
"pgpass": "1.x"
},
"engines": {
"node": ">= 8.0.0"
},
"optionalDependencies": {
"pg-cloudflare": "^1.1.1"
},
"peerDependencies": {
"pg-native": ">=3.0.1"
},
"peerDependenciesMeta": {
"pg-native": {
"optional": true
}
}
},
"node_modules/pg-cloudflare": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz",
"integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==",
"license": "MIT",
"optional": true
},
"node_modules/pg-connection-string": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz",
"integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==",
"license": "MIT"
},
"node_modules/pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
"license": "ISC",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/pg-numeric": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pg-numeric/-/pg-numeric-1.0.2.tgz",
"integrity": "sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==",
"license": "ISC",
"engines": {
"node": ">=4"
}
},
"node_modules/pg-pool": {
"version": "3.8.0",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.8.0.tgz",
"integrity": "sha512-VBw3jiVm6ZOdLBTIcXLNdSotb6Iy3uOCwDGFAksZCXmi10nyRvnP2v3jl4d+IsLYRyXf6o9hIm/ZtUzlByNUdw==",
"license": "MIT",
"peerDependencies": {
"pg": ">=8.0"
}
},
"node_modules/pg-protocol": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.8.0.tgz",
"integrity": "sha512-jvuYlEkL03NRvOoyoRktBK7+qU5kOvlAwvmrH8sr3wbLrOdVWsRxQfz8mMy9sZFsqJ1hEWNfdWKI4SAmoL+j7g==",
"license": "MIT"
},
"node_modules/pg-types": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-4.0.2.tgz",
"integrity": "sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==",
"license": "MIT",
"dependencies": {
"pg-int8": "1.0.1",
"pg-numeric": "1.0.2",
"postgres-array": "~3.0.1",
"postgres-bytea": "~3.0.0",
"postgres-date": "~2.1.0",
"postgres-interval": "^3.0.0",
"postgres-range": "^1.1.1"
},
"engines": {
"node": ">=10"
}
},
"node_modules/pg/node_modules/pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"license": "MIT",
"dependencies": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/pg/node_modules/postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
"license": "MIT",
"engines": {
"node": ">=4"
}
},
"node_modules/pg/node_modules/postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/pg/node_modules/postgres-date": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/pg/node_modules/postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"license": "MIT",
"dependencies": {
"xtend": "^4.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/pgpass": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
"license": "MIT",
"dependencies": {
"split2": "^4.1.0"
}
},
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
@ -3653,6 +3814,51 @@
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="
},
"node_modules/postgres-array": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-3.0.4.tgz",
"integrity": "sha512-nAUSGfSDGOaOAEGwqsRY27GPOea7CNipJPOA7lPbdEpx5Kg3qzdP0AaWC5MlhTWV9s4hFX39nomVZ+C4tnGOJQ==",
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/postgres-bytea": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-3.0.0.tgz",
"integrity": "sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==",
"license": "MIT",
"dependencies": {
"obuf": "~1.1.2"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/postgres-date": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-2.1.0.tgz",
"integrity": "sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==",
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/postgres-interval": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-3.0.0.tgz",
"integrity": "sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==",
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/postgres-range": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/postgres-range/-/postgres-range-1.1.4.tgz",
"integrity": "sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==",
"license": "MIT"
},
"node_modules/preact": {
"version": "10.26.2",
"resolved": "https://registry.npmjs.org/preact/-/preact-10.26.2.tgz",
@ -4112,6 +4318,15 @@
"node": ">=0.10.0"
}
},
"node_modules/split2": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
"license": "ISC",
"engines": {
"node": ">= 10.x"
}
},
"node_modules/streamsearch": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
@ -4382,8 +4597,7 @@
"node_modules/undici-types": {
"version": "6.20.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
"dev": true
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="
},
"node_modules/update-browserslist-db": {
"version": "1.1.2",
@ -4608,6 +4822,15 @@
"node": ">=8"
}
},
"node_modules/xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
"license": "MIT",
"engines": {
"node": ">=0.4"
}
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",

154
node_modules/date-fns/CHANGELOG.md generated vendored
View File

@ -8,11 +8,159 @@ This change log follows the format documented in [Keep a CHANGELOG].
[semantic versioning]: http://semver.org/
[keep a changelog]: http://keepachangelog.com/
Kudos to @kossnocorp, @maximtop, @leshakoss and @tan75 for working on the release.
## v3.6.0 - 2024-03-18
## v3.0.0 - 2023-12-03
On this release worked @kossnocorp and @world1dan. Also, thanks to [@seated](https://github.com/seated) [for sponsoring me](https://github.com/sponsors/kossnocorp).
## Changed
### Fixed
- [Fixed weeks in the Belarisuan locale's `formatDistance`.](https://github.com/date-fns/date-fns/pull/3720)
### Added
- [Added CDN versions of modules compatible with older browsers.](https://github.com/date-fns/date-fns/pull/3737) [See the CDN guide.](https://date-fns.org/docs/CDN)
## v3.5.0 - 2024-03-15
Kudos to @fturmel, @kossnocorp, @makstyle119, @tan75, @marcreichel, @tareknatsheh and @audunru for working on the release. Also, thanks to [@seated](https://github.com/seated) [for sponsoring me](https://github.com/sponsors/kossnocorp).
### Fixed
- [Fixed functions that use current date internally and made them work with date extensions like `UTCDate`.](https://github.com/date-fns/date-fns/issues/3730)
- [Fixed `daysToWeeks` returning negative 0.](https://github.com/date-fns/date-fns/commit/882ced61c692c7c4a79eaaec6eb07cb9c8c9195b)
- [Fixed German grammar for the "half a minute" string.](https://github.com/date-fns/date-fns/pull/3715)
### Added
- [Added the Northern Sámi (`se`) locale.](https://github.com/date-fns/date-fns/pull/3724)
- Added the `constructNow` function that creates the current date using the passed reference date's constructor.
## v3.4.0 - 2024-03-11
Kudos to @kossnocorp, @sakamossan and @Revan99 for working on the release. Also, thanks to [@seated](https://github.com/seated) [for sponsoring me](https://github.com/sponsors/kossnocorp).
### Added
- [Added `roundToNearestHours` function.](https://github.com/date-fns/date-fns/pull/2752)
- [Added Central Kurdish (`ckb`) locale.](https://github.com/date-fns/date-fns/pull/3421)
## v3.3.1 - 2024-01-22
Kudos to @kossnocorp and @fturmel for working on the release.
### Fixed
- Fixed DST issue in `getOverlappingDaysInIntervals`, resulting in an inconsistent number of days returned for intervals starting and ending in different DST periods.
- Fixed functions incorrectly using `trunc` instead of `round`. The bug was introduced in v3.3.0. The affected functions: `differenceInCalendarDays`, `differenceInCalendarISOWeeks`, `differenceInCalendarWeeks`, `getISOWeek`, `getWeek`, and `getISOWeeksInYear`.
## v3.3.0 - 2024-01-20
On this release worked @kossnocorp, @TheKvikk, @fturmel and @ckcherry23.
### Fixed
- Fixed the bug in `getOverlappingDaysInIntervals` caused by incorrect sorting of interval components that led to 0 for timestamps of different lengths.
- Fixed bugs when working with negative numbers caused by using `Math.floor` (`-1.1` → `-2`) instead of `Math.trunc` (`-1.1` → `-1`). Most of the conversion functions (i.e., `hoursToMinutes`) were affected when passing some negative fractional input. Also, some other functions that could be possibly affected by unfortunate timezone/date combinations were fixed.
The functions that were affected: `format`, `parse`, `getUnixTime`, `daysToWeeks`, `hoursToMilliseconds`, `hoursToMinutes`, `hoursToSeconds`, `milliseconds`, `minutesToMilliseconds`, `millisecondsToMinutes`, `monthsToYears`, `millisecondsToHours`, `millisecondsToSeconds`, `minutesToHours`, `minutesToSeconds`, `yearsToQuarters`, `yearsToMonths`, `yearsToDays`, `weeksToDays`, `secondsToMinutes`, `secondsToHours`, `quartersToYears`, `quartersToMonths` and `monthsToQuarters`.
- [Fixed the Czech locale's `formatDistance` to include `1` in `formatDistance`.](https://github.com/date-fns/date-fns/pull/3269)
- Fixed `differenceInSeconds` and other functions relying on rounding options that can produce a negative 0.
- [Added a preprocessor to the locales API, enabling fixing a long-standing bug in the French locale.](https://github.com/date-fns/date-fns/pull/3662) ([#1391](https://github.com/date-fns/date-fns/issues/1391))
- Added missing `yearsToDays` to the FP submodule.
- Made functions using rounding methods always return `0` instead of `-0`.
### Added
- [Added `format` alias `formatDate` with corresponding `FormatDateOptions` interface](https://github.com/date-fns/date-fns/pull/3653).
## v3.2.0 - 2024-01-09
This release is brought to you by @kossnocorp, @fturmel, @grossbart, @MelvinVermeer, and @jcarstairs-scottlogic.
### Fixed
- Fixed types compatability with Lodash's `flow` and fp-ts's `pipe`. ([#3641](https://github.com/date-fns/date-fns/issues/3641))
- [Fixed inconsistent behavior of `roundToNearestMinutes`.](https://github.com/date-fns/date-fns/pull/3132)
### Added
- Added exports of `format`, `lightFormat`, and `parse` internals that enable 3rd-parties to consume those.
## v3.1.0 - 2024-01-05
This release is brought to you by @kossnocorp, @makstyle119 and @dmgawel.
### Fixed
- [Fixed the plural form of weeks in Swedish](https://github.com/date-fns/date-fns/pull/3448).
### Added
- [Added `yearsToDays` function](https://github.com/date-fns/date-fns/pull/3540).
- Added warning about using protected tokens like `Y` or `D` without passing a corresponding option. [See #2950](https://github.com/date-fns/date-fns/issues/2950).
## v3.0.6 - 2023-12-22
On this release worked @imwh0im, @jamcry and @tyrw.
### Fixed
- [Fixed bug in `areIntervalsOverlapping` caused by incorrect sorting](https://github.com/date-fns/date-fns/pull/3628) ([#3614](https://github.com/date-fns/date-fns/issues/3614))
## v3.0.5 - 2023-12-21
This release is brought to you by @goku4199.
### Fixed
- [Fixed internal `toDate` not processing string arguments properly](https://github.com/date-fns/date-fns/pull/3626)
## v3.0.4 - 2023-12-21
This release is brought to you by @kossnocorp.
### Fixed
- Fixed isWithinInterval bug caused by incorrectly sorting dates ([#3623](https://github.com/date-fns/date-fns/issues/3623)).
## v3.0.3 - 2023-12-21
### Fixed
- Rolled back pointing ESM types to the same `d.ts` files. Instead now it copies the content to avoid [the Masquerading as CJS problem](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md) reported by "Are the types wrong?".
## v3.0.2 - 2023-12-21
### Fixed
- Fixed [yet another issue caused by ESM types](https://github.com/date-fns/date-fns/issues/3620) by pointing to the same `d.ts` files.
- [Added `package.json` to exports](https://github.com/date-fns/date-fns/pull/3601) to provide access to tooling.
- [Fixed TypeScript 5.4 build break](https://github.com/date-fns/date-fns/pull/3598) by using the latest type names.
## v3.0.1 - 2023-12-20
### Fixed
- [Fixed an error](https://github.com/date-fns/date-fns/pull/3618) in certain environments caused by `d.mts` files exporting only types.
## v3.0.0 - 2023-12-18
### Changed
- **BREAKING**: date-fns is now a dual-package with the support of both ESM and CommonJS. The files exports are now explicitly in the `package.json`. The ESM files now have `.mjs` extension.

36
node_modules/date-fns/README.md generated vendored
View File

@ -1,36 +1,22 @@
⚠️ **Warning**: the current `main` represents v3 pre-release version of the library. [See `v2` branch](https://github.com/date-fns/date-fns/tree/v2).
🎉️ **NEW**: [date-fns v3 is out!](https://blog.date-fns.org/v3-is-out/)
If you're participating in hacktoberfest, please send your PRs to `main`.
<img alt="date-fns" title="date-fns" src="https://raw.githubusercontent.com/date-fns/date-fns/master/docs/logotype.svg" width="150" />
date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js
👉 [Documentation](https://date-fns.org/)
👉 [Blog](https://blog.date-fns.org/)
<hr>
<p align="center">
<a href="https://date-fns.org/">
<img alt="date-fns" title="date-fns" src="https://raw.githubusercontent.com/date-fns/date-fns/master/docs/logotype.svg" width="300" />
</a>
</p>
<p align="center">
<b>date-fns</b> provides the most comprehensive, yet simple and consistent toolset
<br>
for manipulating <b>JavaScript dates</b> in <b>a browser</b> & <b>Node.js</b>.</b>
</p>
<div align="center">
[📖&nbsp; Documentation](https://date-fns.org/docs/Getting-Started/)&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;[🧑‍💻&nbsp; JavaScript Jobs](https://jobs.date-fns.org/)
</div>
<hr>
# It's like [Lodash](https://lodash.com) for dates
It's like [Lodash](https://lodash.com) for dates
- It has [**200+ functions** for all occasions](https://date-fns.org/docs/Getting-Started/).
- **Modular**: Pick what you need. Works with webpack, Browserify, or Rollup and also supports tree-shaking.
- **Native dates**: Uses existing native type. It doesn't extend core objects for safety's sake.
- **Immutable & Pure**: Built using pure functions and always returns a new date instance.
- **TypeScript & Flow**: Supports both Flow and TypeScript
- **TypeScript**: The library is 100% TypeScript with brand-new handcrafted types.
- **I18n**: Dozens of locales. Include only what you need.
- [and many more benefits](https://date-fns.org/)
@ -58,8 +44,6 @@ To install the package run:
```bash
npm install date-fns --save
# or with yarn
yarn add date-fns
```
## Docs

View File

@ -1 +1,4 @@
export type * from "./addLeadingZeros.d.ts";
export declare function addLeadingZeros(
number: number,
targetLength: number,
): string;

View File

@ -1 +1 @@
export type * from "./defaultLocale.d.ts";
export { enUS as defaultLocale } from "../locale/en-US.js";

View File

@ -1 +1,11 @@
export type * from "./defaultOptions.d.ts";
import type {
FirstWeekContainsDateOptions,
Locale,
LocalizedOptions,
WeekOptions,
} from "../types.js";
export type DefaultOptions = LocalizedOptions<keyof Locale> &
WeekOptions &
FirstWeekContainsDateOptions;
export declare function getDefaultOptions(): DefaultOptions;
export declare function setDefaultOptions(newOptions: DefaultOptions): void;

View File

@ -1 +1,18 @@
export type * from "./formatters.d.ts";
import type { Localize } from "../../locale/types.js";
import type {
FirstWeekContainsDateOptions,
LocalizedOptions,
WeekOptions,
} from "../../types.js";
type Formatter = (
date: Date,
token: string,
localize: Localize,
options: Required<
LocalizedOptions<"options"> & WeekOptions & FirstWeekContainsDateOptions
>,
) => string;
export declare const formatters: {
[token: string]: Formatter;
};
export {};

View File

@ -10,9 +10,7 @@ type Formatter = (
localize: Localize,
options: Required<
LocalizedOptions<"options"> & WeekOptions & FirstWeekContainsDateOptions
> & {
_originalDate: Date;
},
>,
) => string;
export declare const formatters: {
[token: string]: Formatter;

View File

@ -649,9 +649,8 @@ const formatters = (exports.formatters = {
},
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
X: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timezoneOffset = originalDate.getTimezoneOffset();
X: function (date, token, _localize) {
const timezoneOffset = date.getTimezoneOffset();
if (timezoneOffset === 0) {
return "Z";
@ -680,9 +679,8 @@ const formatters = (exports.formatters = {
},
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
x: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timezoneOffset = originalDate.getTimezoneOffset();
x: function (date, token, _localize) {
const timezoneOffset = date.getTimezoneOffset();
switch (token) {
// Hours and optional minutes
@ -707,9 +705,8 @@ const formatters = (exports.formatters = {
},
// Timezone (GMT)
O: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timezoneOffset = originalDate.getTimezoneOffset();
O: function (date, token, _localize) {
const timezoneOffset = date.getTimezoneOffset();
switch (token) {
// Short
@ -725,9 +722,8 @@ const formatters = (exports.formatters = {
},
// Timezone (specific non-location)
z: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timezoneOffset = originalDate.getTimezoneOffset();
z: function (date, token, _localize) {
const timezoneOffset = date.getTimezoneOffset();
switch (token) {
// Short
@ -743,16 +739,14 @@ const formatters = (exports.formatters = {
},
// Seconds timestamp
t: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timestamp = Math.floor(originalDate.getTime() / 1000);
t: function (date, token, _localize) {
const timestamp = Math.trunc(date.getTime() / 1000);
return (0, _index6.addLeadingZeros)(timestamp, token.length);
},
// Milliseconds timestamp
T: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timestamp = originalDate.getTime();
T: function (date, token, _localize) {
const timestamp = date.getTime();
return (0, _index6.addLeadingZeros)(timestamp, token.length);
},
});
@ -760,7 +754,7 @@ const formatters = (exports.formatters = {
function formatTimezoneShort(offset, delimiter = "") {
const sign = offset > 0 ? "-" : "+";
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const hours = Math.trunc(absOffset / 60);
const minutes = absOffset % 60;
if (minutes === 0) {
return sign + String(hours);
@ -781,7 +775,7 @@ function formatTimezoneWithOptionalMinutes(offset, delimiter) {
function formatTimezone(offset, delimiter = "") {
const sign = offset > 0 ? "-" : "+";
const absOffset = Math.abs(offset);
const hours = (0, _index6.addLeadingZeros)(Math.floor(absOffset / 60), 2);
const hours = (0, _index6.addLeadingZeros)(Math.trunc(absOffset / 60), 2);
const minutes = (0, _index6.addLeadingZeros)(absOffset % 60, 2);
return sign + hours + delimiter + minutes;
}

View File

@ -646,9 +646,8 @@ export const formatters = {
},
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
X: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timezoneOffset = originalDate.getTimezoneOffset();
X: function (date, token, _localize) {
const timezoneOffset = date.getTimezoneOffset();
if (timezoneOffset === 0) {
return "Z";
@ -677,9 +676,8 @@ export const formatters = {
},
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
x: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timezoneOffset = originalDate.getTimezoneOffset();
x: function (date, token, _localize) {
const timezoneOffset = date.getTimezoneOffset();
switch (token) {
// Hours and optional minutes
@ -704,9 +702,8 @@ export const formatters = {
},
// Timezone (GMT)
O: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timezoneOffset = originalDate.getTimezoneOffset();
O: function (date, token, _localize) {
const timezoneOffset = date.getTimezoneOffset();
switch (token) {
// Short
@ -722,9 +719,8 @@ export const formatters = {
},
// Timezone (specific non-location)
z: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timezoneOffset = originalDate.getTimezoneOffset();
z: function (date, token, _localize) {
const timezoneOffset = date.getTimezoneOffset();
switch (token) {
// Short
@ -740,16 +736,14 @@ export const formatters = {
},
// Seconds timestamp
t: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timestamp = Math.floor(originalDate.getTime() / 1000);
t: function (date, token, _localize) {
const timestamp = Math.trunc(date.getTime() / 1000);
return addLeadingZeros(timestamp, token.length);
},
// Milliseconds timestamp
T: function (date, token, _localize, options) {
const originalDate = options._originalDate || date;
const timestamp = originalDate.getTime();
T: function (date, token, _localize) {
const timestamp = date.getTime();
return addLeadingZeros(timestamp, token.length);
},
};
@ -757,7 +751,7 @@ export const formatters = {
function formatTimezoneShort(offset, delimiter = "") {
const sign = offset > 0 ? "-" : "+";
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const hours = Math.trunc(absOffset / 60);
const minutes = absOffset % 60;
if (minutes === 0) {
return sign + String(hours);
@ -776,7 +770,7 @@ function formatTimezoneWithOptionalMinutes(offset, delimiter) {
function formatTimezone(offset, delimiter = "") {
const sign = offset > 0 ? "-" : "+";
const absOffset = Math.abs(offset);
const hours = addLeadingZeros(Math.floor(absOffset / 60), 2);
const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
const minutes = addLeadingZeros(absOffset % 60, 2);
return sign + hours + delimiter + minutes;
}

View File

@ -1 +1,11 @@
export type * from "./lightFormatters.d.ts";
export declare const lightFormatters: {
y(date: Date, token: string): string;
M(date: Date, token: string): string;
d(date: Date, token: string): string;
a(date: Date, token: string): string;
h(date: Date, token: string): string;
H(date: Date, token: string): string;
m(date: Date, token: string): string;
s(date: Date, token: string): string;
S(date: Date, token: string): string;
};

View File

@ -94,7 +94,7 @@ const lightFormatters = (exports.lightFormatters = {
S(date, token) {
const numberOfDigits = token.length;
const milliseconds = date.getMilliseconds();
const fractionalSeconds = Math.floor(
const fractionalSeconds = Math.trunc(
milliseconds * Math.pow(10, numberOfDigits - 3),
);
return (0, _index.addLeadingZeros)(fractionalSeconds, token.length);

View File

@ -84,7 +84,7 @@ export const lightFormatters = {
S(date, token) {
const numberOfDigits = token.length;
const milliseconds = date.getMilliseconds();
const fractionalSeconds = Math.floor(
const fractionalSeconds = Math.trunc(
milliseconds * Math.pow(10, numberOfDigits - 3),
);
return addLeadingZeros(fractionalSeconds, token.length);

View File

@ -1 +1,4 @@
export type * from "./longFormatters.d.ts";
import type { FormatLong } from "../../locale/types.js";
type LongFormatter = (pattern: string, formatLong: FormatLong) => string;
export declare const longFormatters: Record<string, LongFormatter>;
export {};

View File

@ -1 +1,14 @@
export type * from "./getTimezoneOffsetInMilliseconds.d.ts";
/**
* Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
* They usually appear for dates that denote time before the timezones were introduced
* (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
* and GMT+01:00:00 after that date)
*
* Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
* which would lead to incorrect calculations.
*
* This function returns the timezone offset in milliseconds that takes seconds in account.
*/
export declare function getTimezoneOffsetInMilliseconds(
date: Date | number | string,
): number;

View File

@ -9,4 +9,6 @@
*
* This function returns the timezone offset in milliseconds that takes seconds in account.
*/
export declare function getTimezoneOffsetInMilliseconds(date: Date): number;
export declare function getTimezoneOffsetInMilliseconds(
date: Date | number | string,
): number;

View File

@ -1,5 +1,8 @@
"use strict";
exports.getTimezoneOffsetInMilliseconds = getTimezoneOffsetInMilliseconds; /**
exports.getTimezoneOffsetInMilliseconds = getTimezoneOffsetInMilliseconds;
var _index = require("../toDate.js");
/**
* Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
* They usually appear for dates that denote time before the timezones were introduced
* (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
@ -11,17 +14,18 @@ exports.getTimezoneOffsetInMilliseconds = getTimezoneOffsetInMilliseconds; /**
* This function returns the timezone offset in milliseconds that takes seconds in account.
*/
function getTimezoneOffsetInMilliseconds(date) {
const _date = (0, _index.toDate)(date);
const utcDate = new Date(
Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
date.getMilliseconds(),
_date.getFullYear(),
_date.getMonth(),
_date.getDate(),
_date.getHours(),
_date.getMinutes(),
_date.getSeconds(),
_date.getMilliseconds(),
),
);
utcDate.setUTCFullYear(date.getFullYear());
return date.getTime() - utcDate.getTime();
utcDate.setUTCFullYear(_date.getFullYear());
return +date - +utcDate;
}

View File

@ -1,3 +1,5 @@
import { toDate } from "../toDate.mjs";
/**
* Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
* They usually appear for dates that denote time before the timezones were introduced
@ -10,17 +12,18 @@
* This function returns the timezone offset in milliseconds that takes seconds in account.
*/
export function getTimezoneOffsetInMilliseconds(date) {
const _date = toDate(date);
const utcDate = new Date(
Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
date.getMilliseconds(),
_date.getFullYear(),
_date.getMonth(),
_date.getDate(),
_date.getHours(),
_date.getMinutes(),
_date.getSeconds(),
_date.getMilliseconds(),
),
);
utcDate.setUTCFullYear(date.getFullYear());
return date.getTime() - utcDate.getTime();
utcDate.setUTCFullYear(_date.getFullYear());
return +date - +utcDate;
}

View File

@ -1 +1,7 @@
export type * from "./protectedTokens.d.ts";
export declare function isProtectedDayOfYearToken(token: string): boolean;
export declare function isProtectedWeekYearToken(token: string): boolean;
export declare function warnOrThrowProtectedError(
token: string,
format: string,
input: string,
): void;

View File

@ -1,6 +1,6 @@
export declare function isProtectedDayOfYearToken(token: string): boolean;
export declare function isProtectedWeekYearToken(token: string): boolean;
export declare function throwProtectedError(
export declare function warnOrThrowProtectedError(
token: string,
format: string,
input: string,

View File

@ -1,34 +1,27 @@
"use strict";
exports.isProtectedDayOfYearToken = isProtectedDayOfYearToken;
exports.isProtectedWeekYearToken = isProtectedWeekYearToken;
exports.throwProtectedError = throwProtectedError;
const protectedDayOfYearTokens = ["D", "DD"];
const protectedWeekYearTokens = ["YY", "YYYY"];
exports.warnOrThrowProtectedError = warnOrThrowProtectedError;
const dayOfYearTokenRE = /^D+$/;
const weekYearTokenRE = /^Y+$/;
const throwTokens = ["D", "DD", "YY", "YYYY"];
function isProtectedDayOfYearToken(token) {
return protectedDayOfYearTokens.indexOf(token) !== -1;
return dayOfYearTokenRE.test(token);
}
function isProtectedWeekYearToken(token) {
return protectedWeekYearTokens.indexOf(token) !== -1;
return weekYearTokenRE.test(token);
}
function throwProtectedError(token, format, input) {
if (token === "YYYY") {
throw new RangeError(
`Use \`yyyy\` instead of \`YYYY\` (in \`${format}\`) for formatting years to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`,
);
} else if (token === "YY") {
throw new RangeError(
`Use \`yy\` instead of \`YY\` (in \`${format}\`) for formatting years to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`,
);
} else if (token === "D") {
throw new RangeError(
`Use \`d\` instead of \`D\` (in \`${format}\`) for formatting days of the month to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`,
);
} else if (token === "DD") {
throw new RangeError(
`Use \`dd\` instead of \`DD\` (in \`${format}\`) for formatting days of the month to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`,
);
}
function warnOrThrowProtectedError(token, format, input) {
const _message = message(token, format, input);
console.warn(_message);
if (throwTokens.includes(token)) throw new RangeError(_message);
}
function message(token, format, input) {
const subject = token[0] === "Y" ? "years" : "days of the month";
return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
}

View File

@ -1,30 +1,23 @@
const protectedDayOfYearTokens = ["D", "DD"];
const protectedWeekYearTokens = ["YY", "YYYY"];
const dayOfYearTokenRE = /^D+$/;
const weekYearTokenRE = /^Y+$/;
const throwTokens = ["D", "DD", "YY", "YYYY"];
export function isProtectedDayOfYearToken(token) {
return protectedDayOfYearTokens.indexOf(token) !== -1;
return dayOfYearTokenRE.test(token);
}
export function isProtectedWeekYearToken(token) {
return protectedWeekYearTokens.indexOf(token) !== -1;
return weekYearTokenRE.test(token);
}
export function throwProtectedError(token, format, input) {
if (token === "YYYY") {
throw new RangeError(
`Use \`yyyy\` instead of \`YYYY\` (in \`${format}\`) for formatting years to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`,
);
} else if (token === "YY") {
throw new RangeError(
`Use \`yy\` instead of \`YY\` (in \`${format}\`) for formatting years to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`,
);
} else if (token === "D") {
throw new RangeError(
`Use \`d\` instead of \`D\` (in \`${format}\`) for formatting days of the month to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`,
);
} else if (token === "DD") {
throw new RangeError(
`Use \`dd\` instead of \`DD\` (in \`${format}\`) for formatting days of the month to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`,
);
}
export function warnOrThrowProtectedError(token, format, input) {
const _message = message(token, format, input);
console.warn(_message);
if (throwTokens.includes(token)) throw new RangeError(_message);
}
function message(token, format, input) {
const subject = token[0] === "Y" ? "years" : "days of the month";
return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
}

View File

@ -1 +0,0 @@
export type * from "./roundingMethods.d.ts";

View File

@ -1,4 +0,0 @@
import type { RoundingMethod } from "../types.js";
export declare function getRoundingMethod(
method: RoundingMethod | undefined,
): (x: number) => number;

View File

@ -1,6 +0,0 @@
"use strict";
exports.getRoundingMethod = getRoundingMethod;
function getRoundingMethod(method) {
return method ? Math[method] : Math.trunc;
}

View File

@ -1,3 +0,0 @@
export function getRoundingMethod(method) {
return method ? Math[method] : Math.trunc;
}

View File

@ -1 +1,3 @@
export type * from "./test.d.ts";
export declare function assertType<T>(_: T): void;
export declare function resetDefaultOptions(): void;
export declare function generateOffset(originalDate: Date): string;

2
node_modules/date-fns/_lib/test.js generated vendored
View File

@ -20,7 +20,7 @@ function generateOffset(originalDate) {
if (tzOffset !== 0) {
const absoluteOffset = Math.abs(tzOffset);
const hourOffset = (0, _index.addLeadingZeros)(
Math.floor(absoluteOffset / 60),
Math.trunc(absoluteOffset / 60),
2,
);
const minuteOffset = (0, _index.addLeadingZeros)(absoluteOffset % 60, 2);

View File

@ -15,7 +15,7 @@ export function generateOffset(originalDate) {
if (tzOffset !== 0) {
const absoluteOffset = Math.abs(tzOffset);
const hourOffset = addLeadingZeros(Math.floor(absoluteOffset / 60), 2);
const hourOffset = addLeadingZeros(Math.trunc(absoluteOffset / 60), 2);
const minuteOffset = addLeadingZeros(absoluteOffset % 60, 2);
// If less than 0, the sign is +, because it is ahead of time.
const sign = tzOffset < 0 ? "+" : "-";

46
node_modules/date-fns/add.d.mts generated vendored
View File

@ -1 +1,45 @@
export type * from "./add.d.ts";
import type { Duration } from "./types.js";
/**
* @name add
* @category Common Helpers
* @summary Add the specified years, months, weeks, days, hours, minutes and seconds to the given date.
*
* @description
* Add the specified years, months, weeks, days, hours, minutes and seconds to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added.
*
* | Key | Description |
* |----------------|------------------------------------|
* | years | Amount of years to be added |
* | months | Amount of months to be added |
* | weeks | Amount of weeks to be added |
* | days | Amount of days to be added |
* | hours | Amount of hours to be added |
* | minutes | Amount of minutes to be added |
* | seconds | Amount of seconds to be added |
*
* All values default to 0
*
* @returns The new date with the seconds added
*
* @example
* // Add the following duration to 1 September 2014, 10:19:50
* const result = add(new Date(2014, 8, 1, 10, 19, 50), {
* years: 2,
* months: 9,
* weeks: 1,
* days: 7,
* hours: 5,\\-7
* minutes: 9,
* seconds: 30,
* })
* //=> Thu Jun 15 2017 15:29:20
*/
export declare function add<DateType extends Date>(
date: DateType | number | string,
duration: Duration,
): DateType;

2
node_modules/date-fns/add.d.ts generated vendored
View File

@ -10,7 +10,7 @@ import type { Duration } from "./types.js";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added.
*
* | Key | Description |
* |----------------|------------------------------------|

2
node_modules/date-fns/add.js generated vendored
View File

@ -16,7 +16,7 @@ var _index4 = require("./toDate.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added.
*
* | Key | Description |
* |----------------|------------------------------------|

2
node_modules/date-fns/add.mjs generated vendored
View File

@ -14,7 +14,7 @@ import { toDate } from "./toDate.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added.
*
* | Key | Description |
* |----------------|------------------------------------|

View File

@ -1 +1,24 @@
export type * from "./addBusinessDays.d.ts";
/**
* @name addBusinessDays
* @category Date Extension Helpers
* @summary Add the specified number of business days (mon - fri) to the given date.
*
* @description
* Add the specified number of business days (mon - fri) to the given date, ignoring weekends.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of business days to be added.
*
* @returns The new date with the business days added
*
* @example
* // Add 10 business days to 1 September 2014:
* const result = addBusinessDays(new Date(2014, 8, 1), 10)
* //=> Mon Sep 15 2014 00:00:00 (skipped weekend days)
*/
export declare function addBusinessDays<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of business days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of business days to be added.
*
* @returns The new date with the business days added
*

View File

@ -17,7 +17,7 @@ var _index5 = require("./toDate.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of business days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of business days to be added.
*
* @returns The new date with the business days added
*

View File

@ -15,7 +15,7 @@ import { toDate } from "./toDate.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of business days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of business days to be added.
*
* @returns The new date with the business days added
*

25
node_modules/date-fns/addDays.d.mts generated vendored
View File

@ -1 +1,24 @@
export type * from "./addDays.d.ts";
/**
* @name addDays
* @category Day Helpers
* @summary Add the specified number of days to the given date.
*
* @description
* Add the specified number of days to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of days to be added.
*
* @returns The new date with the days added
*
* @example
* // Add 10 days to 1 September 2014:
* const result = addDays(new Date(2014, 8, 1), 10)
* //=> Thu Sep 11 2014 00:00:00
*/
export declare function addDays<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

2
node_modules/date-fns/addDays.d.ts generated vendored
View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of days to be added.
*
* @returns The new date with the days added
*

2
node_modules/date-fns/addDays.js generated vendored
View File

@ -14,7 +14,7 @@ var _index2 = require("./constructFrom.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of days to be added.
*
* @returns The new date with the days added
*

2
node_modules/date-fns/addDays.mjs generated vendored
View File

@ -12,7 +12,7 @@ import { constructFrom } from "./constructFrom.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of days to be added.
*
* @returns The new date with the days added
*

25
node_modules/date-fns/addHours.d.mts generated vendored
View File

@ -1 +1,24 @@
export type * from "./addHours.d.ts";
/**
* @name addHours
* @category Hour Helpers
* @summary Add the specified number of hours to the given date.
*
* @description
* Add the specified number of hours to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of hours to be added.
*
* @returns The new date with the hours added
*
* @example
* // Add 2 hours to 10 July 2014 23:00:00:
* const result = addHours(new Date(2014, 6, 10, 23, 0), 2)
* //=> Fri Jul 11 2014 01:00:00
*/
export declare function addHours<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of hours to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of hours to be added.
*
* @returns The new date with the hours added
*

2
node_modules/date-fns/addHours.js generated vendored
View File

@ -14,7 +14,7 @@ var _index2 = require("./constants.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of hours to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of hours to be added.
*
* @returns The new date with the hours added
*

2
node_modules/date-fns/addHours.mjs generated vendored
View File

@ -12,7 +12,7 @@ import { millisecondsInHour } from "./constants.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of hours to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of hours to be added.
*
* @returns The new date with the hours added
*

View File

@ -1 +1,26 @@
export type * from "./addISOWeekYears.d.ts";
/**
* @name addISOWeekYears
* @category ISO Week-Numbering Year Helpers
* @summary Add the specified number of ISO week-numbering years to the given date.
*
* @description
* Add the specified number of ISO week-numbering years to the given date.
*
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of ISO week-numbering years to be added.
*
* @returns The new date with the ISO week-numbering years added
*
* @example
* // Add 5 ISO week-numbering years to 2 July 2010:
* const result = addISOWeekYears(new Date(2010, 6, 2), 5)
* //=> Fri Jn 26 2015 00:00:00
*/
export declare function addISOWeekYears<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -11,7 +11,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of ISO week-numbering years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of ISO week-numbering years to be added.
*
* @returns The new date with the ISO week-numbering years added
*

View File

@ -16,7 +16,7 @@ var _index2 = require("./setISOWeekYear.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of ISO week-numbering years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of ISO week-numbering years to be added.
*
* @returns The new date with the ISO week-numbering years added
*

View File

@ -14,7 +14,7 @@ import { setISOWeekYear } from "./setISOWeekYear.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of ISO week-numbering years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of ISO week-numbering years to be added.
*
* @returns The new date with the ISO week-numbering years added
*

View File

@ -1 +1,24 @@
export type * from "./addMilliseconds.d.ts";
/**
* @name addMilliseconds
* @category Millisecond Helpers
* @summary Add the specified number of milliseconds to the given date.
*
* @description
* Add the specified number of milliseconds to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of milliseconds to be added.
*
* @returns The new date with the milliseconds added
*
* @example
* // Add 750 milliseconds to 10 July 2014 12:45:30.000:
* const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
* //=> Thu Jul 10 2014 12:45:30.750
*/
export declare function addMilliseconds<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of milliseconds to be added.
*
* @returns The new date with the milliseconds added
*

View File

@ -14,7 +14,7 @@ var _index2 = require("./constructFrom.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of milliseconds to be added.
*
* @returns The new date with the milliseconds added
*

View File

@ -12,7 +12,7 @@ import { constructFrom } from "./constructFrom.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of milliseconds to be added.
*
* @returns The new date with the milliseconds added
*

View File

@ -1 +1,24 @@
export type * from "./addMinutes.d.ts";
/**
* @name addMinutes
* @category Minute Helpers
* @summary Add the specified number of minutes to the given date.
*
* @description
* Add the specified number of minutes to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of minutes to be added.
*
* @returns The new date with the minutes added
*
* @example
* // Add 30 minutes to 10 July 2014 12:00:00:
* const result = addMinutes(new Date(2014, 6, 10, 12, 0), 30)
* //=> Thu Jul 10 2014 12:30:00
*/
export declare function addMinutes<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of minutes to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of minutes to be added.
*
* @returns The new date with the minutes added
*

View File

@ -14,7 +14,7 @@ var _index2 = require("./constants.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of minutes to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of minutes to be added.
*
* @returns The new date with the minutes added
*

View File

@ -12,7 +12,7 @@ import { millisecondsInMinute } from "./constants.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of minutes to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of minutes to be added.
*
* @returns The new date with the minutes added
*

View File

@ -1 +1,28 @@
export type * from "./addMonths.d.ts";
/**
* @name addMonths
* @category Month Helpers
* @summary Add the specified number of months to the given date.
*
* @description
* Add the specified number of months to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of months to be added.
*
* @returns The new date with the months added
*
* @example
* // Add 5 months to 1 September 2014:
* const result = addMonths(new Date(2014, 8, 1), 5)
* //=> Sun Feb 01 2015 00:00:00
*
* // Add one month to 30 January 2023:
* const result = addMonths(new Date(2023, 0, 30), 1)
* //=> Tue Feb 28 2023 00:00:00
*/
export declare function addMonths<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of months to be added.
*
* @returns The new date with the months added
*

2
node_modules/date-fns/addMonths.js generated vendored
View File

@ -14,7 +14,7 @@ var _index2 = require("./constructFrom.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of months to be added.
*
* @returns The new date with the months added
*

View File

@ -12,7 +12,7 @@ import { constructFrom } from "./constructFrom.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of months to be added.
*
* @returns The new date with the months added
*

View File

@ -1 +1,24 @@
export type * from "./addQuarters.d.ts";
/**
* @name addQuarters
* @category Quarter Helpers
* @summary Add the specified number of year quarters to the given date.
*
* @description
* Add the specified number of year quarters to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of quarters to be added.
*
* @returns The new date with the quarters added
*
* @example
* // Add 1 quarter to 1 September 2014:
* const result = addQuarters(new Date(2014, 8, 1), 1)
* //=> Mon Dec 01 2014 00:00:00
*/
export declare function addQuarters<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of quarters to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of quarters to be added.
*
* @returns The new date with the quarters added
*

View File

@ -13,7 +13,7 @@ var _index = require("./addMonths.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of quarters to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of quarters to be added.
*
* @returns The new date with the quarters added
*

View File

@ -11,7 +11,7 @@ import { addMonths } from "./addMonths.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of quarters to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of quarters to be added.
*
* @returns The new date with the quarters added
*

View File

@ -1 +1,24 @@
export type * from "./addSeconds.d.ts";
/**
* @name addSeconds
* @category Second Helpers
* @summary Add the specified number of seconds to the given date.
*
* @description
* Add the specified number of seconds to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of seconds to be added.
*
* @returns The new date with the seconds added
*
* @example
* // Add 30 seconds to 10 July 2014 12:45:00:
* const result = addSeconds(new Date(2014, 6, 10, 12, 45, 0), 30)
* //=> Thu Jul 10 2014 12:45:30
*/
export declare function addSeconds<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of seconds to be added.
*
* @returns The new date with the seconds added
*

View File

@ -13,7 +13,7 @@ var _index = require("./addMilliseconds.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of seconds to be added.
*
* @returns The new date with the seconds added
*

View File

@ -11,7 +11,7 @@ import { addMilliseconds } from "./addMilliseconds.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of seconds to be added.
*
* @returns The new date with the seconds added
*

25
node_modules/date-fns/addWeeks.d.mts generated vendored
View File

@ -1 +1,24 @@
export type * from "./addWeeks.d.ts";
/**
* @name addWeeks
* @category Week Helpers
* @summary Add the specified number of weeks to the given date.
*
* @description
* Add the specified number of week to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of weeks to be added.
*
* @returns The new date with the weeks added
*
* @example
* // Add 4 weeks to 1 September 2014:
* const result = addWeeks(new Date(2014, 8, 1), 4)
* //=> Mon Sep 29 2014 00:00:00
*/
export declare function addWeeks<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of weeks to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of weeks to be added.
*
* @returns The new date with the weeks added
*

2
node_modules/date-fns/addWeeks.js generated vendored
View File

@ -13,7 +13,7 @@ var _index = require("./addDays.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of weeks to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of weeks to be added.
*
* @returns The new date with the weeks added
*

2
node_modules/date-fns/addWeeks.mjs generated vendored
View File

@ -11,7 +11,7 @@ import { addDays } from "./addDays.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of weeks to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of weeks to be added.
*
* @returns The new date with the weeks added
*

25
node_modules/date-fns/addYears.d.mts generated vendored
View File

@ -1 +1,24 @@
export type * from "./addYears.d.ts";
/**
* @name addYears
* @category Year Helpers
* @summary Add the specified number of years to the given date.
*
* @description
* Add the specified number of years to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of years to be added.
*
* @returns The new date with the years added
*
* @example
* // Add 5 years to 1 September 2014:
* const result = addYears(new Date(2014, 8, 1), 5)
* //=> Sun Sep 01 2019 00:00:00
*/
export declare function addYears<DateType extends Date>(
date: DateType | number | string,
amount: number,
): DateType;

View File

@ -9,7 +9,7 @@
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of years to be added.
*
* @returns The new date with the years added
*

2
node_modules/date-fns/addYears.js generated vendored
View File

@ -13,7 +13,7 @@ var _index = require("./addMonths.js");
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of years to be added.
*
* @returns The new date with the years added
*

2
node_modules/date-fns/addYears.mjs generated vendored
View File

@ -11,7 +11,7 @@ import { addMonths } from "./addMonths.mjs";
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be changed
* @param amount - The amount of years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @param amount - The amount of years to be added.
*
* @returns The new date with the years added
*

View File

@ -1 +1,67 @@
export type * from "./areIntervalsOverlapping.d.ts";
import type { Interval } from "./types.js";
/**
* The {@link areIntervalsOverlapping} function options.
*/
export interface AreIntervalsOverlappingOptions {
/** Whether the comparison is inclusive or not */
inclusive?: boolean;
}
/**
* @name areIntervalsOverlapping
* @category Interval Helpers
* @summary Is the given time interval overlapping with another time interval?
*
* @description
* Is the given time interval overlapping with another time interval? Adjacent intervals do not count as overlapping unless `inclusive` is set to `true`.
*
* @param intervalLeft - The first interval to compare.
* @param intervalRight - The second interval to compare.
* @param options - The object with options
*
* @returns Whether the time intervals are overlapping
*
* @example
* // For overlapping time intervals:
* areIntervalsOverlapping(
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
* { start: new Date(2014, 0, 17), end: new Date(2014, 0, 21) }
* )
* //=> true
*
* @example
* // For non-overlapping time intervals:
* areIntervalsOverlapping(
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
* { start: new Date(2014, 0, 21), end: new Date(2014, 0, 22) }
* )
* //=> false
*
* @example
* // For adjacent time intervals:
* areIntervalsOverlapping(
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
* { start: new Date(2014, 0, 20), end: new Date(2014, 0, 30) }
* )
* //=> false
*
* @example
* // Using the inclusive option:
* areIntervalsOverlapping(
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
* { start: new Date(2014, 0, 20), end: new Date(2014, 0, 24) }
* )
* //=> false
*
* @example
* areIntervalsOverlapping(
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
* { start: new Date(2014, 0, 20), end: new Date(2014, 0, 24) },
* { inclusive: true }
* )
* //=> true
*/
export declare function areIntervalsOverlapping(
intervalLeft: Interval,
intervalRight: Interval,
options?: AreIntervalsOverlappingOptions,
): boolean;

View File

@ -64,11 +64,11 @@ function areIntervalsOverlapping(intervalLeft, intervalRight, options) {
const [leftStartTime, leftEndTime] = [
+(0, _index.toDate)(intervalLeft.start),
+(0, _index.toDate)(intervalLeft.end),
].sort();
].sort((a, b) => a - b);
const [rightStartTime, rightEndTime] = [
+(0, _index.toDate)(intervalRight.start),
+(0, _index.toDate)(intervalRight.end),
].sort();
].sort((a, b) => a - b);
if (options?.inclusive)
return leftStartTime <= rightEndTime && rightStartTime <= leftEndTime;

View File

@ -62,11 +62,11 @@ export function areIntervalsOverlapping(intervalLeft, intervalRight, options) {
const [leftStartTime, leftEndTime] = [
+toDate(intervalLeft.start),
+toDate(intervalLeft.end),
].sort();
].sort((a, b) => a - b);
const [rightStartTime, rightEndTime] = [
+toDate(intervalRight.start),
+toDate(intervalRight.end),
].sort();
].sort((a, b) => a - b);
if (options?.inclusive)
return leftStartTime <= rightEndTime && rightStartTime <= leftEndTime;

34
node_modules/date-fns/clamp.d.mts generated vendored
View File

@ -1 +1,33 @@
export type * from "./clamp.d.ts";
import type { Interval } from "./types.js";
/**
* @name clamp
* @category Interval Helpers
* @summary Return a date bounded by the start and the end of the given interval
*
* @description
* Clamps a date to the lower bound with the start of the interval and the upper
* bound with the end of the interval.
*
* - When the date is less than the start of the interval, the start is returned.
* - When the date is greater than the end of the interval, the end is returned.
* - Otherwise the date is returned.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date to be bounded
* @param interval - The interval to bound to
*
* @returns The date bounded by the start and the end of the interval
*
* @example
* // What is Mar, 21, 2021 bounded to an interval starting at Mar, 22, 2021 and ending at Apr, 01, 2021
* const result = clamp(new Date(2021, 2, 21), {
* start: new Date(2021, 2, 22),
* end: new Date(2021, 3, 1),
* })
* //=> Mon Mar 22 2021 00:00:00
*/
export declare function clamp<DateType extends Date>(
date: DateType | number | string,
interval: Interval,
): DateType | Date;

View File

@ -1 +1,30 @@
export type * from "./closestIndexTo.d.ts";
/**
* @name closestIndexTo
* @category Common Helpers
* @summary Return an index of the closest date from the array comparing to the given date.
*
* @description
* Return an index of the closest date from the array comparing to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param dateToCompare - The date to compare with
* @param dates - The array to search
*
* @returns An index of the date closest to the given date or undefined if no valid value is given
*
* @example
* // Which date is closer to 6 September 2015?
* const dateToCompare = new Date(2015, 8, 6)
* const datesArray = [
* new Date(2015, 0, 1),
* new Date(2016, 0, 1),
* new Date(2017, 0, 1)
* ]
* const result = closestIndexTo(dateToCompare, datesArray)
* //=> 1
*/
export declare function closestIndexTo<DateType extends Date>(
dateToCompare: DateType | number | string,
dates: Array<DateType | number | string>,
): number | undefined;

View File

@ -1 +1,28 @@
export type * from "./closestTo.d.ts";
/**
* @name closestTo
* @category Common Helpers
* @summary Return a date from the array closest to the given date.
*
* @description
* Return a date from the array closest to the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param dateToCompare - The date to compare with
* @param dates - The array to search
*
* @returns The date from the array closest to the given date or undefined if no valid value is given
*
* @example
* // Which date is closer to 6 September 2015: 1 January 2000 or 1 January 2030?
* const dateToCompare = new Date(2015, 8, 6)
* const result = closestTo(dateToCompare, [
* new Date(2000, 0, 1),
* new Date(2030, 0, 1)
* ])
* //=> Tue Jan 01 2030 00:00:00
*/
export declare function closestTo<DateType extends Date>(
dateToCompare: DateType | number | string,
dates: Array<DateType | number | string>,
): DateType | undefined;

View File

@ -1 +1,38 @@
export type * from "./compareAsc.d.ts";
/**
* @name compareAsc
* @category Common Helpers
* @summary Compare the two dates and return -1, 0 or 1.
*
* @description
* Compare the two dates and return 1 if the first date is after the second,
* -1 if the first date is before the second or 0 if dates are equal.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param dateLeft - The first date to compare
* @param dateRight - The second date to compare
*
* @returns The result of the comparison
*
* @example
* // Compare 11 February 1987 and 10 July 1989:
* const result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10))
* //=> -1
*
* @example
* // Sort the array of dates:
* const result = [
* new Date(1995, 6, 2),
* new Date(1987, 1, 11),
* new Date(1989, 6, 10)
* ].sort(compareAsc)
* //=> [
* // Wed Feb 11 1987 00:00:00,
* // Mon Jul 10 1989 00:00:00,
* // Sun Jul 02 1995 00:00:00
* // ]
*/
export declare function compareAsc<DateType extends Date>(
dateLeft: DateType | number | string,
dateRight: DateType | number | string,
): number;

View File

@ -1 +1,38 @@
export type * from "./compareDesc.d.ts";
/**
* @name compareDesc
* @category Common Helpers
* @summary Compare the two dates reverse chronologically and return -1, 0 or 1.
*
* @description
* Compare the two dates and return -1 if the first date is after the second,
* 1 if the first date is before the second or 0 if dates are equal.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param dateLeft - The first date to compare
* @param dateRight - The second date to compare
*
* @returns The result of the comparison
*
* @example
* // Compare 11 February 1987 and 10 July 1989 reverse chronologically:
* const result = compareDesc(new Date(1987, 1, 11), new Date(1989, 6, 10))
* //=> 1
*
* @example
* // Sort the array of dates in reverse chronological order:
* const result = [
* new Date(1995, 6, 2),
* new Date(1987, 1, 11),
* new Date(1989, 6, 10)
* ].sort(compareDesc)
* //=> [
* // Sun Jul 02 1995 00:00:00,
* // Mon Jul 10 1989 00:00:00,
* // Wed Feb 11 1987 00:00:00
* // ]
*/
export declare function compareDesc<DateType extends Date>(
dateLeft: DateType | number | string,
dateRight: DateType | number | string,
): number;

181
node_modules/date-fns/constants.d.mts generated vendored
View File

@ -1 +1,180 @@
export type * from "./constants.d.ts";
/**
* @module constants
* @summary Useful constants
* @description
* Collection of useful date constants.
*
* The constants could be imported from `date-fns/constants`:
*
* ```ts
* import { maxTime, minTime } from "./constants/date-fns/constants";
*
* function isAllowedTime(time) {
* return time <= maxTime && time >= minTime;
* }
* ```
*/
/**
* @constant
* @name daysInWeek
* @summary Days in 1 week.
*/
export declare const daysInWeek = 7;
/**
* @constant
* @name daysInYear
* @summary Days in 1 year.
*
* @description
* How many days in a year.
*
* One years equals 365.2425 days according to the formula:
*
* > Leap year occures every 4 years, except for years that are divisable by 100 and not divisable by 400.
* > 1 mean year = (365+1/4-1/100+1/400) days = 365.2425 days
*/
export declare const daysInYear = 365.2425;
/**
* @constant
* @name maxTime
* @summary Maximum allowed time.
*
* @example
* import { maxTime } from "./constants/date-fns/constants";
*
* const isValid = 8640000000000001 <= maxTime;
* //=> false
*
* new Date(8640000000000001);
* //=> Invalid Date
*/
export declare const maxTime: number;
/**
* @constant
* @name minTime
* @summary Minimum allowed time.
*
* @example
* import { minTime } from "./constants/date-fns/constants";
*
* const isValid = -8640000000000001 >= minTime;
* //=> false
*
* new Date(-8640000000000001)
* //=> Invalid Date
*/
export declare const minTime: number;
/**
* @constant
* @name millisecondsInWeek
* @summary Milliseconds in 1 week.
*/
export declare const millisecondsInWeek = 604800000;
/**
* @constant
* @name millisecondsInDay
* @summary Milliseconds in 1 day.
*/
export declare const millisecondsInDay = 86400000;
/**
* @constant
* @name millisecondsInMinute
* @summary Milliseconds in 1 minute
*/
export declare const millisecondsInMinute = 60000;
/**
* @constant
* @name millisecondsInHour
* @summary Milliseconds in 1 hour
*/
export declare const millisecondsInHour = 3600000;
/**
* @constant
* @name millisecondsInSecond
* @summary Milliseconds in 1 second
*/
export declare const millisecondsInSecond = 1000;
/**
* @constant
* @name minutesInYear
* @summary Minutes in 1 year.
*/
export declare const minutesInYear = 525600;
/**
* @constant
* @name minutesInMonth
* @summary Minutes in 1 month.
*/
export declare const minutesInMonth = 43200;
/**
* @constant
* @name minutesInDay
* @summary Minutes in 1 day.
*/
export declare const minutesInDay = 1440;
/**
* @constant
* @name minutesInHour
* @summary Minutes in 1 hour.
*/
export declare const minutesInHour = 60;
/**
* @constant
* @name monthsInQuarter
* @summary Months in 1 quarter.
*/
export declare const monthsInQuarter = 3;
/**
* @constant
* @name monthsInYear
* @summary Months in 1 year.
*/
export declare const monthsInYear = 12;
/**
* @constant
* @name quartersInYear
* @summary Quarters in 1 year
*/
export declare const quartersInYear = 4;
/**
* @constant
* @name secondsInHour
* @summary Seconds in 1 hour.
*/
export declare const secondsInHour = 3600;
/**
* @constant
* @name secondsInMinute
* @summary Seconds in 1 minute.
*/
export declare const secondsInMinute = 60;
/**
* @constant
* @name secondsInDay
* @summary Seconds in 1 day.
*/
export declare const secondsInDay: number;
/**
* @constant
* @name secondsInWeek
* @summary Seconds in 1 week.
*/
export declare const secondsInWeek: number;
/**
* @constant
* @name secondsInYear
* @summary Seconds in 1 year.
*/
export declare const secondsInYear: number;
/**
* @constant
* @name secondsInMonth
* @summary Seconds in 1 month
*/
export declare const secondsInMonth: number;
/**
* @constant
* @name secondsInQuarter
* @summary Seconds in 1 quarter.
*/
export declare const secondsInQuarter: number;

View File

@ -1 +1,34 @@
export type * from "./constructFrom.d.ts";
/**
* @name constructFrom
* @category Generic Helpers
* @summary Constructs a date using the reference date and the value
*
* @description
* The function constructs a new date using the constructor from the reference
* date and the given value. It helps to build generic functions that accept
* date extensions.
*
* It defaults to `Date` if the passed reference date is a number or a string.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The reference date to take constructor from
* @param value - The value to create the date
*
* @returns Date initialized using the given date and value
*
* @example
* import { constructFrom } from 'date-fns'
*
* // A function that clones a date preserving the original type
* function cloneDate<DateType extends Date(date: DateType): DateType {
* return constructFrom(
* date, // Use contrustor from the given date
* date.getTime() // Use the date value to create a new date
* )
* }
*/
export declare function constructFrom<DateType extends Date>(
date: DateType | number | string,
value: Date | number | string,
): DateType;

View File

@ -8,6 +8,8 @@
* date and the given value. It helps to build generic functions that accept
* date extensions.
*
* It defaults to `Date` if the passed reference date is a number or a string.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The reference date to take constructor from

View File

@ -11,6 +11,8 @@ exports.constructFrom = constructFrom;
* date and the given value. It helps to build generic functions that accept
* date extensions.
*
* It defaults to `Date` if the passed reference date is a number or a string.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The reference date to take constructor from

View File

@ -8,6 +8,8 @@
* date and the given value. It helps to build generic functions that accept
* date extensions.
*
* It defaults to `Date` if the passed reference date is a number or a string.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The reference date to take constructor from

View File

@ -1 +1,25 @@
export type * from "./daysToWeeks.d.ts";
/**
* @name daysToWeeks
* @category Conversion Helpers
* @summary Convert days to weeks.
*
* @description
* Convert a number of days to a full number of weeks.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param days - The number of days to be converted
*
* @returns The number of days converted in weeks
*
* @example
* // Convert 14 days to weeks:
* const result = daysToWeeks(14)
* //=> 2
*
* @example
* // It uses trunc rounding:
* const result = daysToWeeks(13)
* //=> 1
*/
export declare function daysToWeeks(days: number): number;

View File

@ -18,7 +18,7 @@
* //=> 2
*
* @example
* // It uses floor rounding:
* // It uses trunc rounding:
* const result = daysToWeeks(13)
* //=> 1
*/

View File

@ -22,11 +22,13 @@ var _index = require("./constants.js");
* //=> 2
*
* @example
* // It uses floor rounding:
* // It uses trunc rounding:
* const result = daysToWeeks(13)
* //=> 1
*/
function daysToWeeks(days) {
const weeks = days / _index.daysInWeek;
return Math.floor(weeks);
const result = Math.trunc(weeks);
// Prevent negative zero
return result === 0 ? 0 : result;
}

View File

@ -20,13 +20,15 @@ import { daysInWeek } from "./constants.mjs";
* //=> 2
*
* @example
* // It uses floor rounding:
* // It uses trunc rounding:
* const result = daysToWeeks(13)
* //=> 1
*/
export function daysToWeeks(days) {
const weeks = days / daysInWeek;
return Math.floor(weeks);
const result = Math.trunc(weeks);
// Prevent negative zero
return result === 0 ? 0 : result;
}
// Fallback for modularized imports:

View File

@ -1 +1,55 @@
export type * from "./differenceInBusinessDays.d.ts";
/**
* @name differenceInBusinessDays
* @category Day Helpers
* @summary Get the number of business days between the given dates.
*
* @description
* Get the number of business day periods between the given dates.
* Business days being days that arent in the weekend.
* Like `differenceInCalendarDays`, the function removes the times from
* the dates before calculating the difference.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param dateLeft - The later date
* @param dateRight - The earlier date
*
* @returns The number of business days
*
* @example
* // How many business days are between
* // 10 January 2014 and 20 July 2014?
* const result = differenceInBusinessDays(
* new Date(2014, 6, 20),
* new Date(2014, 0, 10)
* )
* //=> 136
*
* // How many business days are between
* // 30 November 2021 and 1 November 2021?
* const result = differenceInBusinessDays(
* new Date(2021, 10, 30),
* new Date(2021, 10, 1)
* )
* //=> 21
*
* // How many business days are between
* // 1 November 2021 and 1 December 2021?
* const result = differenceInBusinessDays(
* new Date(2021, 10, 1),
* new Date(2021, 11, 1)
* )
* //=> -22
*
* // How many business days are between
* // 1 November 2021 and 1 November 2021 ?
* const result = differenceInBusinessDays(
* new Date(2021, 10, 1),
* new Date(2021, 10, 1)
* )
* //=> 0
*/
export declare function differenceInBusinessDays<DateType extends Date>(
dateLeft: DateType | number | string,
dateRight: DateType | number | string,
): number;

View File

@ -1 +1,36 @@
export type * from "./differenceInCalendarDays.d.ts";
/**
* @name differenceInCalendarDays
* @category Day Helpers
* @summary Get the number of calendar days between the given dates.
*
* @description
* Get the number of calendar days between the given dates. This means that the times are removed
* from the dates and then the difference in days is calculated.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param dateLeft - The later date
* @param dateRight - The earlier date
*
* @returns The number of calendar days
*
* @example
* // How many calendar days are between
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
* const result = differenceInCalendarDays(
* new Date(2012, 6, 2, 0, 0),
* new Date(2011, 6, 2, 23, 0)
* )
* //=> 366
* // How many calendar days are between
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
* const result = differenceInCalendarDays(
* new Date(2011, 6, 3, 0, 1),
* new Date(2011, 6, 2, 23, 59)
* )
* //=> 1
*/
export declare function differenceInCalendarDays<DateType extends Date>(
dateLeft: DateType | number | string,
dateRight: DateType | number | string,
): number;

View File

@ -41,15 +41,15 @@ function differenceInCalendarDays(dateLeft, dateRight) {
const startOfDayRight = (0, _index2.startOfDay)(dateRight);
const timestampLeft =
startOfDayLeft.getTime() -
+startOfDayLeft -
(0, _index3.getTimezoneOffsetInMilliseconds)(startOfDayLeft);
const timestampRight =
startOfDayRight.getTime() -
+startOfDayRight -
(0, _index3.getTimezoneOffsetInMilliseconds)(startOfDayRight);
// Round the number of days to the nearest integer
// because the number of milliseconds in a day is not constant
// (e.g. it's different in the day of the daylight saving time clock shift)
// Round the number of days to the nearest integer because the number of
// milliseconds in a day is not constant (e.g. it's different in the week of
// the daylight saving time clock shift).
return Math.round(
(timestampLeft - timestampRight) / _index.millisecondsInDay,
);

Some files were not shown because too many files have changed in this diff Show More