Module: BlackStack::Strings::DateTime
- Defined in:
- lib/functions.rb
Overview
DateTime
Class Method Summary collapse
-
.datetime_api_check(s) ⇒ Object
Check the string has the format yyyymmddhhmmss.
-
.datetime_api_to_sql(s) ⇒ Object
Convierte un string con formato api-datatime (yyyymmddhhmmss) a un string con formato sql-datetime (yyyy-mm-dd hh:mm:ss).
-
.datetime_sql_check(s) ⇒ Object
Check the string has the format yyyy-mm-dd hh:mm:ss.
-
.datetime_sql_to_api(s) ⇒ Object
Convierte un string con formato sql-datatime a un string con formato sql-datetime.
Class Method Details
.datetime_api_check(s) ⇒ Object
Check the string has the format yyyymmddhhmmss.
> Return true if success. Otherwise, return false.
> Year cannot be lower than 1900.
> Year cannot be higher or equal than 2100.
668 669 670 671 672 673 674 675 676 677 |
# File 'lib/functions.rb', line 668 def self.datetime_api_check(s) return false if (s.size!=14) year = s[0..3] month = s[4..5] day = s[6..7] hour = s[8..9] minute = s[10..11] second = s[12..13] BlackStack::DateTime::Misc::datetime_values_check(year,month,day,hour,minute,second) end |
.datetime_api_to_sql(s) ⇒ Object
Convierte un string con formato api-datatime (yyyymmddhhmmss) a un string con formato sql-datetime (yyyy-mm-dd hh:mm:ss).
695 696 697 698 699 700 701 702 703 704 705 |
# File 'lib/functions.rb', line 695 def self.datetime_api_to_sql(s) raise "Wrong Api DataTime Format." if (datetime_api_check(s)==false) year = s[0..3] month = s[4..5] day = s[6..7] hour = s[8..9] minute = s[10..11] second = s[12..13] ret = "#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}" return ret end |
.datetime_sql_check(s) ⇒ Object
Check the string has the format yyyy-mm-dd hh:mm:ss.
> Return true if success. Otherwise, return false.
> Year cannot be lower than 1900.
> Year cannot be higher or equal than 2100.
683 684 685 686 687 688 689 690 691 692 |
# File 'lib/functions.rb', line 683 def self.datetime_sql_check(s) return false if (s.size!=19) year = s[0..3] month = s[5..6] day = s[8..9] hour = s[11..12] minute = s[14..15] second = s[17..18] BlackStack::DateTime::Misc::datetime_values_check(year,month,day,hour,minute,second) end |
.datetime_sql_to_api(s) ⇒ Object
Convierte un string con formato sql-datatime a un string con formato sql-datetime.
708 709 710 711 712 713 714 715 716 717 718 |
# File 'lib/functions.rb', line 708 def self.datetime_sql_to_api(s) raise "Wrong SQL DataTime Format." if (datetime_sql_check(s)==false) year = s[0..3] month = s[5..6] day = s[8..9] hour = s[11..12] minute = s[14..15] second = s[17..18] ret = "#{year}#{month}#{day}#{hour}#{minute}#{second}" return ret end |