1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package timefmt
- import (
- "strings"
- "time"
- )
- type TimeFormatterEx struct {
- Parser *FormatParser
- Printer *TimePrinterEx
- Multiline bool
- }
- func (this *TimeFormatterEx) Format(t time.Time, exdata map[string]string) string {
- fs := this.Printer.PrintTimeEx(t, exdata)
- if this.Multiline {
- return fs
- } else {
- fs = strings.Replace(fs, "\r", "", -1)
- fs = strings.Replace(fs, "\n", "", -1)
- return fs
- }
- }
- func (this *TimeFormatterEx) ForceTimezone(tz *time.Location) {
- this.Printer.UseTimezone(tz)
- }
- func (this *TimeFormatterEx) ForceLocalTimezone() {
- this.Printer.UseLocalTimezone()
- }
- func (this *TimeFormatterEx) ForceUTC() {
- this.Printer.UseUTC()
- }
- func (this *TimeFormatterEx) ParseFormat(fmtstr string) {
- this.Parser.ParseFormatString(&FormatPrinterParsingAbstract{
- isEx: true,
- tp: nil,
- tpe: this.Printer,
- }, fmtstr)
- }
- func NewDefaultTimeFormatterEx(fmtstr string, multiline bool) *TimeFormatterEx {
- tf := &TimeFormatterEx{
- Printer: NewTimePrinterEx(),
- Multiline: multiline,
- Parser: NewFormatParser(true),
- }
- tf.ParseFormat(fmtstr)
- return tf
- }
- func NewTimeFormatterEx(printer *TimePrinterEx, parser *FormatParser, multiline bool) *TimeFormatterEx {
- tf := &TimeFormatterEx{
- Printer: printer,
- Multiline: multiline,
- Parser: parser,
- }
- return tf
- }
|