Fix datetime bug

This commit is contained in:
2025-06-25 06:34:07 +00:00
parent af3eae56c8
commit 71164657a1
3 changed files with 40 additions and 33 deletions
+8 -8
View File
@@ -1,9 +1,9 @@
import { useState, useEffect, useCallback } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as FileSystem from 'expo-file-system';
import { DATA_DIRECTORY_URI_KEY } from '@/constants/Settings';
import { StorageAccessFramework } from 'expo-file-system';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { format } from 'date-fns';
import * as FileSystem from 'expo-file-system';
import { StorageAccessFramework } from 'expo-file-system';
import { useCallback, useEffect, useState } from 'react';
interface FileEntry {
name: string;
@@ -22,7 +22,7 @@ interface FileInfoWithSize {
size: number;
}
function datetimeFromFilename(filename: string): string {
function datetimeFromFilename(filename: string): Date {
const match = filename.match(/(\d+)-(\d+)-(\d+)-(\d+)-(\d+)-(\d+)\.md$/);
if (match) {
const [_, year, month, day, hour, minute, second] = match;
@@ -33,9 +33,9 @@ function datetimeFromFilename(filename: string): string {
parseInt(hour),
parseInt(minute),
parseInt(second)
).toISOString();
);
}
return new Date().toISOString();
return new Date();
}
export function prettyName(uri: string | null, options: PrettyNameOptions = {}) {
@@ -118,7 +118,7 @@ export function useFileSystem() {
}
markdownFiles.sort((a, b) => b.datetime.getTime() - a.datetime.getTime()); // Sort by datetime descending
setFiles(markdownFiles);
setDirectorySize(totalSize);
setDirectorySize(Math.round((totalSize / 1024 / 1024) * 1000) / 1000); // Convert to MB
} catch (error) {
console.error('Error loading files:', error);
}