Documentation
¶
Index ¶
- func GetFormatLayout(format FormatType) string
- func IsValidFormat(format string) bool
- type DSTInfo
- type DSTTransitionInfo
- type FormatTimeInput
- type FormatTimeResult
- type FormatType
- type GetTimeInput
- type GetTimeResult
- type ParseTimeInput
- type ParseTimeResult
- type TimeService
- type TimezoneInfo
- type TimezoneInfoInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFormatLayout ¶
func GetFormatLayout(format FormatType) string
GetFormatLayout returns the Go time layout for a given format type
func IsValidFormat ¶
IsValidFormat checks if a format type is supported
Types ¶
type DSTInfo ¶
type DSTInfo struct {
Start time.Time `json:"start"`
End time.Time `json:"end"`
Saving time.Duration `json:"saving"`
}
DSTInfo contains DST period information
type DSTTransitionInfo ¶
type DSTTransitionInfo struct {
NextTransition time.Time `json:"next_transition"`
TransitionType string `json:"transition_type"` // "enter_dst" or "exit_dst"
OffsetChange int `json:"offset_change"` // seconds
}
DSTTransitionInfo contains information about DST transitions
type FormatTimeInput ¶
type FormatTimeInput struct {
Timestamp interface{} `json:"timestamp"` // can be string, int, or time.Time
Format string `json:"format"`
Timezone string `json:"timezone,omitempty"`
}
FormatTimeInput represents input for formatting time
type FormatTimeResult ¶
type FormatTimeResult struct {
FormattedTime string `json:"formatted_time"`
Timezone string `json:"timezone"`
Format string `json:"format"`
UnixTimestamp int64 `json:"unix_timestamp"`
}
FormatTimeResult represents the result of formatting time
type FormatType ¶
type FormatType string
FormatType represents supported time format types
const ( FormatRFC3339 FormatType = "RFC3339" FormatRFC3339Nano FormatType = "RFC3339Nano" FormatUnix FormatType = "Unix" FormatUnixMilli FormatType = "UnixMilli" FormatUnixMicro FormatType = "UnixMicro" FormatUnixNano FormatType = "UnixNano" FormatLayout FormatType = "Layout" )
type GetTimeInput ¶
type GetTimeInput struct {
Timezone string `json:"timezone,omitempty"`
Format string `json:"format,omitempty"`
}
GetTimeInput represents input for getting current time
type GetTimeResult ¶
type GetTimeResult struct {
FormattedTime string `json:"formatted_time"`
Timezone string `json:"timezone"`
Format string `json:"format"`
UnixTimestamp int64 `json:"unix_timestamp"`
}
GetTimeResult represents the result of getting current time
type ParseTimeInput ¶
type ParseTimeInput struct {
TimeString string `json:"time_string"`
Format string `json:"format,omitempty"`
Timezone string `json:"timezone,omitempty"`
}
ParseTimeInput represents input for parsing time strings
type ParseTimeResult ¶
type ParseTimeResult struct {
UnixTimestamp int64 `json:"unix_timestamp"`
RFC3339 string `json:"rfc3339"`
Timezone string `json:"timezone"`
IsDST bool `json:"is_dst"`
}
ParseTimeResult represents the result of parsing time
type TimeService ¶
type TimeService interface {
// GetCurrentTime returns the current time in the specified timezone and format
GetCurrentTime(input GetTimeInput) (GetTimeResult, error)
// FormatTime formats a timestamp using the specified format and timezone
FormatTime(input FormatTimeInput) (FormatTimeResult, error)
// ParseTime parses a time string and returns timestamp information
ParseTime(input ParseTimeInput) (ParseTimeResult, error)
// GetTimezoneInfo returns information about a timezone
GetTimezoneInfo(input TimezoneInfoInput) (TimezoneInfo, error)
// ConvertTimezone converts a time from one timezone to another (kept for internal use)
ConvertTimezone(t time.Time, fromTZ, toTZ string) (time.Time, error)
// IsFormatSupported checks if a format is supported
IsFormatSupported(format string) bool
// GetSupportedFormats returns a list of supported formats
GetSupportedFormats() []string
}
TimeService defines the interface for time operations
func NewTimeService ¶
func NewTimeService(defaultTimezone, defaultFormat string, supportedFormats []string, logger *zap.Logger) TimeService
NewTimeService creates a new time service instance
type TimezoneInfo ¶
type TimezoneInfo struct {
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
Offset string `json:"offset"`
OffsetSeconds int `json:"offset_seconds"`
IsDST bool `json:"is_dst"`
DST *DSTInfo `json:"dst,omitempty"`
DSTTransition *DSTTransitionInfo `json:"dst_transition,omitempty"` // Keep for backward compatibility
}
TimezoneInfo contains information about a timezone
type TimezoneInfoInput ¶
type TimezoneInfoInput struct {
Timezone string `json:"timezone"`
ReferenceTime time.Time `json:"reference_time,omitempty"`
}
TimezoneInfoInput represents input for timezone information