Skip to content

Commit a6e9d57

Browse files
committed
♻️ refactor: update codebase #2
1 parent f2dade5 commit a6e9d57

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

entry.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,3 +932,65 @@ func MustParseInLocation(loc *time.Location, s ...string) time.Time {
932932
func Between(time1, time2 string) bool {
933933
return With(time.Now()).Between(time1, time2)
934934
}
935+
936+
// FormatRFC formats the time using the provided layout.
937+
//
938+
// Parameters:
939+
// - `layout`: A TimeFormatRFC value representing the layout to use for formatting.
940+
//
941+
// Returns:
942+
// - A string representing the formatted time.
943+
//
944+
// Example:
945+
//
946+
// formatted := FormatRFC(TimeFormat20060102T150405) // Returns the formatted time in the format "2023-08-15 13:45:30".
947+
func FormatRFC(layout TimeFormatRFC) string {
948+
return With(time.Now()).FormatRFC(layout)
949+
}
950+
951+
// FormatRFCshort formats the time using the provided layout.
952+
//
953+
// Parameters:
954+
// - `layout`: A TimeRFC value representing the layout to use for formatting.
955+
//
956+
// Returns:
957+
// - A string representing the formatted time.
958+
//
959+
// Example:
960+
//
961+
// formatted := FormatRFCshort(TimeRFC01T150405) // Returns the formatted time in the format "13:45:30".
962+
func FormatRFCshort(layout TimeRFC) string {
963+
return With(time.Now()).FormatRFCshort(layout)
964+
}
965+
966+
// FormatRFC formats the time using the provided layout.
967+
//
968+
// Parameters:
969+
// - `v`: A time.Time value representing the time to format.
970+
// - `layout`: A TimeFormatRFC value representing the layout to use for formatting.
971+
//
972+
// Returns:
973+
// - A string representing the formatted time.
974+
//
975+
// Example:
976+
//
977+
// formatted := FormatRFC(v, TimeFormat20060102T150405) // Returns the formatted time in the format "2023-08-15 13:45:30".
978+
func FFormatRFC(v time.Time, layout TimeFormatRFC) string {
979+
return With(v).FormatRFC(layout)
980+
}
981+
982+
// FormatRFCshort formats the time using the provided layout.
983+
//
984+
// Parameters:
985+
// - `v`: A time.Time value representing the time to format.
986+
// - `layout`: A TimeRFC value representing the layout to use for formatting.
987+
//
988+
// Returns:
989+
// - A string representing the formatted time.
990+
//
991+
// Example:
992+
//
993+
// formatted := FormatRFCshort(v, TimeRFC01T150405) // Returns the formatted time in the format "13:45:30".
994+
func FFormatRFCshort(v time.Time, layout TimeRFC) string {
995+
return With(v).FormatRFCshort(layout)
996+
}

time.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,38 @@ func (t *Timex) Between(begin, end string) bool {
718718
return t.After(beginTime) && t.Before(endTime)
719719
}
720720

721+
// FormatRFC formats the time using the provided layout.
722+
//
723+
// Parameters:
724+
// - `layout`: A TimeFormatRFC value representing the layout to use for formatting.
725+
//
726+
// Returns:
727+
// - A string representing the formatted time.
728+
//
729+
// Example:
730+
//
731+
// t := Timex{Time: time.Now()}
732+
// formatted := t.FormatRFC(TimeFormat20060102T150405) // Returns the formatted time in the format "2023-08-15 13:45:30".
733+
func (t *Timex) FormatRFC(layout TimeFormatRFC) string {
734+
return t.Time.Format(string(layout))
735+
}
736+
737+
// FormatRFCshort formats the time using the provided layout.
738+
//
739+
// Parameters:
740+
// - `layout`: A TimeRFC value representing the layout to use for formatting.
741+
//
742+
// Returns:
743+
// - A string representing the formatted time.
744+
//
745+
// Example:
746+
//
747+
// t := Timex{Time: time.Now()}
748+
// formatted := t.FormatRFCshort(TimeRFC01T150405) // Returns the formatted time in the format "13:45:30".
749+
func (t *Timex) FormatRFCshort(layout TimeRFC) string {
750+
return t.Time.Format(string(layout))
751+
}
752+
721753
// parseWithFormat attempts to parse a given date/time string `s` using a series of predefined formats
722754
// specified in the `TimeFormats` slice of the Timex instance. It tries to parse the string in the provided
723755
// `location` and returns the parsed time value or an error if parsing fails.

0 commit comments

Comments
 (0)