11package nepalitime
22
33import (
4- "errors"
54 "strconv"
65 "strings"
76)
@@ -14,7 +13,7 @@ type NepaliFormatter struct {
1413 nepaliTime * NepaliTime
1514}
1615
17- func (obj * NepaliFormatter ) Format (format string ) ( string , error ) {
16+ func (obj * NepaliFormatter ) Format (format string ) string {
1817 index , num , timeStr := 0 , len (format ), ""
1918
2019 for index < num {
@@ -32,17 +31,11 @@ func (obj *NepaliFormatter) Format(format string) (string, error) {
3231 if (index + 1 ) < num {
3332 index ++
3433 char = string (format [index ])
35- res , err := obj .getFormatString (specialChar + char )
36- if err != nil {
37- return "" , errors .New ("error while formatting NepaliTime with given format" )
38- }
34+ res := obj .getFormatString (specialChar + char )
3935 timeStr += res
4036 }
4137 } else {
42- res , err := obj .getFormatString (char )
43- if err != nil {
44- return "" , errors .New ("error while formatting NepaliTime with given format" )
45- }
38+ res := obj .getFormatString (char )
4639 timeStr += res
4740 }
4841 index ++
@@ -51,48 +44,49 @@ func (obj *NepaliFormatter) Format(format string) (string, error) {
5144 }
5245 }
5346
54- return timeStr , nil
47+ return timeStr
5548}
5649
5750// utility method that operates based on the type of directive
58- func (obj * NepaliFormatter ) getFormatString (directive string ) ( string , error ) {
51+ func (obj * NepaliFormatter ) getFormatString (directive string ) string {
5952 switch directive {
6053 case "d" :
61- return obj .day_ (), nil
54+ return obj .day_ ()
6255 case "-d" :
63- return obj .dayNonzero (), nil
56+ return obj .dayNonzero ()
6457 case "m" :
65- return obj .monthNumber (), nil
58+ return obj .monthNumber ()
6659 case "-m" :
67- return obj .monthNumberNonzero (), nil
60+ return obj .monthNumberNonzero ()
6861 case "y" :
69- return obj .yearHalf (), nil
62+ return obj .yearHalf ()
7063 case "Y" :
71- return obj .yearFull (), nil
64+ return obj .yearFull ()
7265 case "H" :
73- return obj .hour24 (), nil
66+ return obj .hour24 ()
7467 case "-H" :
75- return obj .hour24Nonzero (), nil
68+ return obj .hour24Nonzero ()
7669 case "I" :
77- return obj .hour12 (), nil
70+ return obj .hour12 ()
7871 case "-I" :
79- return obj .hour12Nonzero (), nil
72+ return obj .hour12Nonzero ()
8073 case "p" :
81- return obj .ampm (), nil
74+ return obj .ampm ()
8275 case "M" :
83- return obj .minute (), nil
76+ return obj .minute ()
8477 case "-M" :
85- return obj .minuteNonzero (), nil
78+ return obj .minuteNonzero ()
8679 case "S" :
87- return obj .second (), nil
80+ return obj .second ()
8881 case "-S" :
89- return obj .secondNonzero (), nil
82+ return obj .secondNonzero ()
9083 case "f" :
91- return obj .nanosecond_ (), nil
84+ return obj .nanosecond_ ()
9285 case "-f" :
93- return obj .nanosecondNonZero (), nil
86+ return obj .nanosecondNonZero ()
9487 default :
95- return "" , errors .New ("error while getting format string for passed directive" )
88+ // if not match return the directive
89+ return "%" + directive
9690 }
9791}
9892
0 commit comments