@@ -820,48 +820,76 @@ public static function timeAgoInWords($dateTime, $options = array()) {
820
820
return __d ('cake ' , 'on %s ' , date ($ format , $ inSeconds ));
821
821
}
822
822
823
- $ f = $ accuracy ['second ' ];
823
+ $ fWord = $ accuracy ['second ' ];
824
824
if ($ years > 0 ) {
825
- $ f = $ accuracy ['year ' ];
825
+ $ fWord = $ accuracy ['year ' ];
826
826
} elseif (abs ($ months ) > 0 ) {
827
- $ f = $ accuracy ['month ' ];
827
+ $ fWord = $ accuracy ['month ' ];
828
828
} elseif (abs ($ weeks ) > 0 ) {
829
- $ f = $ accuracy ['week ' ];
829
+ $ fWord = $ accuracy ['week ' ];
830
830
} elseif (abs ($ days ) > 0 ) {
831
- $ f = $ accuracy ['day ' ];
831
+ $ fWord = $ accuracy ['day ' ];
832
832
} elseif (abs ($ hours ) > 0 ) {
833
- $ f = $ accuracy ['hour ' ];
833
+ $ fWord = $ accuracy ['hour ' ];
834
834
} elseif (abs ($ minutes ) > 0 ) {
835
- $ f = $ accuracy ['minute ' ];
835
+ $ fWord = $ accuracy ['minute ' ];
836
836
}
837
837
838
- $ f = str_replace (array ('year ' , 'month ' , 'week ' , 'day ' , 'hour ' , 'minute ' , 'second ' ), array (1 , 2 , 3 , 4 , 5 , 6 , 7 ), $ f );
838
+ $ fNum = str_replace (array ('year ' , 'month ' , 'week ' , 'day ' , 'hour ' , 'minute ' , 'second ' ), array (1 , 2 , 3 , 4 , 5 , 6 , 7 ), $ fWord );
839
839
840
840
$ relativeDate = '' ;
841
- if ($ f >= 1 && $ years > 0 ) {
841
+ if ($ fNum >= 1 && $ years > 0 ) {
842
842
$ relativeDate .= ($ relativeDate ? ', ' : '' ) . __dn ('cake ' , '%d year ' , '%d years ' , $ years , $ years );
843
843
}
844
- if ($ f >= 2 && $ months > 0 ) {
844
+ if ($ fNum >= 2 && $ months > 0 ) {
845
845
$ relativeDate .= ($ relativeDate ? ', ' : '' ) . __dn ('cake ' , '%d month ' , '%d months ' , $ months , $ months );
846
846
}
847
- if ($ f >= 3 && $ weeks > 0 ) {
847
+ if ($ fNum >= 3 && $ weeks > 0 ) {
848
848
$ relativeDate .= ($ relativeDate ? ', ' : '' ) . __dn ('cake ' , '%d week ' , '%d weeks ' , $ weeks , $ weeks );
849
849
}
850
- if ($ f >= 4 && $ days > 0 ) {
850
+ if ($ fNum >= 4 && $ days > 0 ) {
851
851
$ relativeDate .= ($ relativeDate ? ', ' : '' ) . __dn ('cake ' , '%d day ' , '%d days ' , $ days , $ days );
852
852
}
853
- if ($ f >= 5 && $ hours > 0 ) {
853
+ if ($ fNum >= 5 && $ hours > 0 ) {
854
854
$ relativeDate .= ($ relativeDate ? ', ' : '' ) . __dn ('cake ' , '%d hour ' , '%d hours ' , $ hours , $ hours );
855
855
}
856
- if ($ f >= 6 && $ minutes > 0 ) {
856
+ if ($ fNum >= 6 && $ minutes > 0 ) {
857
857
$ relativeDate .= ($ relativeDate ? ', ' : '' ) . __dn ('cake ' , '%d minute ' , '%d minutes ' , $ minutes , $ minutes );
858
858
}
859
- if ($ f >= 7 && $ seconds > 0 ) {
859
+ if ($ fNum >= 7 && $ seconds > 0 ) {
860
860
$ relativeDate .= ($ relativeDate ? ', ' : '' ) . __dn ('cake ' , '%d second ' , '%d seconds ' , $ seconds , $ seconds );
861
861
}
862
862
863
+ $ aboutAgo = array (
864
+ 'second ' => __d ('cake ' , 'about a second ago ' ),
865
+ 'minute ' => __d ('cake ' , 'about a minute ago ' ),
866
+ 'hour ' => __d ('cake ' , 'about an hour ago ' ),
867
+ 'day ' => __d ('cake ' , 'about a day ago ' ),
868
+ 'week ' => __d ('cake ' , 'about a week ago ' ),
869
+ 'year ' => __d ('cake ' , 'about a year ago ' )
870
+ );
871
+
872
+ $ aboutIn = array (
873
+ 'second ' => __d ('cake ' , 'in about a second ' ),
874
+ 'minute ' => __d ('cake ' , 'in about a minute ' ),
875
+ 'hour ' => __d ('cake ' , 'in about an hour ' ),
876
+ 'day ' => __d ('cake ' , 'in about a day ' ),
877
+ 'week ' => __d ('cake ' , 'in about a week ' ),
878
+ 'year ' => __d ('cake ' , 'in about a year ' )
879
+ );
880
+
881
+ // When time has passed
863
882
if (!$ backwards ) {
864
- return __d ('cake ' , '%s ago ' , $ relativeDate );
883
+ if ($ relativeDate ) {
884
+ return __d ('cake ' , '%s ago ' , $ relativeDate );
885
+ }
886
+
887
+ return $ aboutAgo [$ fWord ];
888
+ }
889
+
890
+ // When time is to come
891
+ if (!$ relativeDate ) {
892
+ return $ aboutIn [$ fWord ];
865
893
}
866
894
867
895
return $ relativeDate ;
0 commit comments