Skip to content

Commit 57fa22b

Browse files
committed
loopdb: remove unused code
1 parent d6be549 commit 57fa22b

File tree

2 files changed

+0
-198
lines changed

2 files changed

+0
-198
lines changed

loopdb/sql_test.go

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -384,82 +384,6 @@ func TestIssue615(t *testing.T) {
384384
require.NoError(t, err)
385385
}
386386

387-
func TestTimeConversions(t *testing.T) {
388-
tests := []struct {
389-
timeString string
390-
expectedTime time.Time
391-
}{
392-
{
393-
timeString: "2018-11-01 00:00:00 +0000 UTC",
394-
expectedTime: time.Date(2018, 11, 1, 0, 0, 0, 0, time.UTC),
395-
},
396-
{
397-
timeString: "2018-11-01 00:00:01.10000 +0000 UTC",
398-
expectedTime: time.Date(2018, 11, 1, 0, 0, 1, 100000000, time.UTC),
399-
},
400-
{
401-
timeString: "2053-12-29T02:40:44.269009408Z",
402-
expectedTime: time.Date(
403-
time.Now().Year(), 12, 29, 2, 40, 44, 269009408, time.UTC,
404-
),
405-
},
406-
{
407-
timeString: "55563-06-27 02:09:24 +0000 UTC",
408-
expectedTime: time.Date(
409-
time.Now().Year(), 6, 27, 2, 9, 24, 0, time.UTC,
410-
),
411-
},
412-
{
413-
timeString: "2172-03-11 10:01:11.849906176 +0000 UTC",
414-
expectedTime: time.Date(
415-
time.Now().Year(), 3, 11, 10, 1, 11, 849906176, time.UTC,
416-
),
417-
},
418-
{
419-
timeString: "2023-08-04 16:07:49 +0800 CST",
420-
expectedTime: time.Date(
421-
2023, 8, 4, 8, 7, 49, 0, time.UTC,
422-
),
423-
},
424-
{
425-
timeString: "2023-08-04 16:07:49 -0700 MST",
426-
expectedTime: time.Date(
427-
2023, 8, 4, 23, 7, 49, 0, time.UTC,
428-
),
429-
},
430-
{
431-
timeString: "2023-08-04T16:07:49+08:00",
432-
expectedTime: time.Date(
433-
2023, 8, 4, 8, 7, 49, 0, time.UTC,
434-
),
435-
},
436-
{
437-
timeString: "2023-08-04T16:07:49+08:00",
438-
expectedTime: time.Date(
439-
2023, 8, 4, 8, 7, 49, 0, time.UTC,
440-
),
441-
},
442-
{
443-
timeString: "2188-02-29 15:34:23.847906176 +0000 UTC",
444-
expectedTime: time.Date(
445-
2023, 2, 28, 15, 34, 23, 847906176, time.UTC,
446-
),
447-
},
448-
{
449-
timeString: "2188-02-29T16:07:49+08:00",
450-
expectedTime: time.Date(
451-
2023, 2, 28, 8, 7, 49, 0, time.UTC,
452-
),
453-
},
454-
}
455-
456-
for _, test := range tests {
457-
time, err := fixTimeStamp(test.timeString)
458-
require.NoError(t, err)
459-
require.Equal(t, test.expectedTime, time)
460-
}
461-
}
462-
463387
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
464388

465389
func randomString(length int) string {

loopdb/sqlite.go

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package loopdb
33
import (
44
"context"
55
"database/sql"
6-
"errors"
76
"fmt"
87
"net/url"
98
"path/filepath"
@@ -325,92 +324,6 @@ func (r *SqliteTxOptions) ReadOnly() bool {
325324
return r.readOnly
326325
}
327326

328-
// fixTimeStamp tries to parse a timestamp string with both the
329-
// parseSqliteTimeStamp and parsePostgresTimeStamp functions.
330-
// If both fail, it returns an error.
331-
func fixTimeStamp(dateTimeStr string) (time.Time, error) {
332-
year, err := getTimeStampYear(dateTimeStr)
333-
if err != nil {
334-
return time.Time{}, err
335-
}
336-
337-
// If the year is in the future. It was a faulty timestamp.
338-
thisYear := time.Now().Year()
339-
if year > thisYear {
340-
dateTimeStr = strings.Replace(
341-
dateTimeStr,
342-
fmt.Sprintf("%d", year),
343-
fmt.Sprintf("%d", thisYear),
344-
1,
345-
)
346-
}
347-
348-
// If the year is a leap year and the date is 29th of February, we
349-
// need to change it to 28th of February. Otherwise, the time.Parse
350-
// function will fail, as a non-leap year cannot have 29th of February.
351-
day, month, err := extractDayAndMonth(dateTimeStr)
352-
if err != nil {
353-
return time.Time{}, fmt.Errorf("unable to parse timestamp day "+
354-
"and month %v: %v", dateTimeStr, err)
355-
}
356-
357-
if !isLeapYear(thisYear) &&
358-
month == 2 && day == 29 {
359-
360-
dateTimeStr = strings.Replace(
361-
dateTimeStr,
362-
fmt.Sprintf("%d-02-29", thisYear),
363-
fmt.Sprintf("%d-02-28", thisYear),
364-
1,
365-
)
366-
}
367-
368-
parsedTime, err := parseLayouts(defaultLayouts(), dateTimeStr)
369-
if err != nil {
370-
return time.Time{}, fmt.Errorf("unable to parse timestamp %v: %v",
371-
dateTimeStr, err)
372-
}
373-
374-
return parsedTime.UTC(), nil
375-
}
376-
377-
// parseLayouts parses time based on a list of provided layouts.
378-
// If layouts is empty list or nil, the error with unknown layout will be returned.
379-
func parseLayouts(layouts []string, dateTime string) (time.Time, error) {
380-
for _, layout := range layouts {
381-
parsedTime, err := time.Parse(layout, dateTime)
382-
if err == nil {
383-
return parsedTime, nil
384-
}
385-
}
386-
387-
return time.Time{}, errors.New("unknown layout")
388-
}
389-
390-
// defaultLayouts returns a default list of ALL supported layouts.
391-
// This function returns new copy of a slice.
392-
func defaultLayouts() []string {
393-
return []string{
394-
"2006-01-02 15:04:05.99999 -0700 MST", // Custom sqlite layout.
395-
time.RFC3339Nano,
396-
time.RFC3339,
397-
time.RFC1123Z,
398-
time.RFC1123,
399-
time.RFC850,
400-
time.RFC822Z,
401-
time.RFC822,
402-
time.Layout,
403-
time.RubyDate,
404-
time.UnixDate,
405-
time.ANSIC,
406-
time.StampNano,
407-
time.StampMicro,
408-
time.StampMilli,
409-
time.Stamp,
410-
time.Kitchen,
411-
}
412-
}
413-
414327
// getTimeStampYear returns the year of a timestamp string.
415328
func getTimeStampYear(dateTimeStr string) (int, error) {
416329
parts := strings.Split(dateTimeStr, "-")
@@ -426,38 +339,3 @@ func getTimeStampYear(dateTimeStr string) (int, error) {
426339

427340
return year, nil
428341
}
429-
430-
// extractDayAndMonth extracts the day and month from a date string.
431-
func extractDayAndMonth(dateStr string) (int, int, error) {
432-
// Split the date string into parts using various delimiters.
433-
parts := strings.FieldsFunc(dateStr, func(r rune) bool {
434-
return r == '-' || r == ' ' || r == 'T' || r == ':' || r == '+' || r == 'Z'
435-
})
436-
437-
if len(parts) < 3 {
438-
return 0, 0, fmt.Errorf("Invalid date format: %s", dateStr)
439-
}
440-
441-
// Extract year, month, and day from the parts.
442-
_, err := strconv.Atoi(parts[0])
443-
if err != nil {
444-
return 0, 0, err
445-
}
446-
447-
month, err := strconv.Atoi(parts[1])
448-
if err != nil {
449-
return 0, 0, err
450-
}
451-
452-
day, err := strconv.Atoi(parts[2])
453-
if err != nil {
454-
return 0, 0, err
455-
}
456-
457-
return day, month, nil
458-
}
459-
460-
// isLeapYear returns true if the year is a leap year.
461-
func isLeapYear(year int) bool {
462-
return (year%4 == 0 && year%100 != 0) || (year%400 == 0)
463-
}

0 commit comments

Comments
 (0)