Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

dateUtils.business.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Created by robin on 12/29/16.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('appSdk')
  7. .factory('DateUtilsBusiness', [
  8. function() {
  9. var DateUtilsBusiness = {};
  10. var dateFormat = 'DD MMM YYYY'; //TODO
  11. var timeFormat = 'HH[h]mm'; //TODO
  12. var dateTimeFormat = dateFormat + ' ' + timeFormat; //TODO
  13. DateUtilsBusiness.areSameDates = function(date1, date2)
  14. {
  15. if (date1 == null || date2 == null) {
  16. return date1 == date2;
  17. }
  18. return date1.getTime() == date2.getTime();
  19. };
  20. DateUtilsBusiness.format = function (date, format) {
  21. if (date == null) {
  22. return null;
  23. }
  24. return moment(date).format(format);
  25. };
  26. DateUtilsBusiness.formatDate = function(date)
  27. {
  28. return DateUtilsBusiness.format(date, dateFormat);
  29. };
  30. DateUtilsBusiness.formatTime = function(date)
  31. {
  32. return DateUtilsBusiness.format(date, timeFormat);
  33. };
  34. DateUtilsBusiness.formatDateTime = function(date)
  35. {
  36. return DateUtilsBusiness.format(date, dateTimeFormat);
  37. };
  38. DateUtilsBusiness.parse = function(date, format, strict)
  39. {
  40. if (date == null) {
  41. return null;
  42. }
  43. if (strict == null) {
  44. strict = true;
  45. }
  46. var d = moment(date, format, strict);
  47. if (d.isValid()) {
  48. return d.toDate();
  49. }
  50. return null;
  51. };
  52. DateUtilsBusiness.parseDate = function(date, strict)
  53. {
  54. return DateUtilsBusiness.parse(date, dateFormat, strict);
  55. };
  56. DateUtilsBusiness.parseTime = function(date, strict)
  57. {
  58. return DateUtilsBusiness.parse(date, timeFormat, strict);
  59. };
  60. DateUtilsBusiness.parseDateTime = function(date, strict)
  61. {
  62. return DateUtilsBusiness.parse(date, dateTimeFormat, strict);
  63. };
  64. return DateUtilsBusiness;
  65. }]);
  66. })();