您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

59 行
2.0 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. import webnotes
  24. import datetime
  25. # global values -- used for caching
  26. user_date_format = None
  27. dateformats = {
  28. 'yyyy-mm-dd': '%Y-%m-%d',
  29. 'dd/mm/yyyy': '%d/%m/%Y',
  30. 'mm/dd/yyyy': '%m/%d/%Y',
  31. 'dd-mm-yyyy': '%d-%m-%Y',
  32. 'dd-mmm-yyyy': '%d-%b-%Y', # numbers app format
  33. 'yyyy-mm-dd': '%Y-%m-%d',
  34. }
  35. def user_to_str(date, date_format=None, verbose=1):
  36. if not date: return date
  37. if not date_format:
  38. date_format = get_user_date_format()
  39. try:
  40. return datetime.datetime.strptime(date,
  41. dateformats[date_format]).strftime('%Y-%m-%d')
  42. except ValueError, e:
  43. if verbose:
  44. webnotes.msgprint("Date %s must be in format %s" % (date, date_format),
  45. raise_exception=True)
  46. else:
  47. raise e
  48. def get_user_date_format():
  49. if not user_date_format:
  50. global user_date_format
  51. user_date_format = webnotes.conn.get_value("Control Panel", None, "date_format")
  52. return user_date_format