best-globals 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/best-globals.js +26 -3
  2. package/package.json +1 -1
package/best-globals.js CHANGED
@@ -461,7 +461,7 @@ bestGlobals.Datetime.prototype.getTime = function getTime() {
461
461
  ).getTime();
462
462
  };
463
463
 
464
- bestGlobals.Datetime.prototype.toPlainString = function toPlainString(){
464
+ bestGlobals.Datetime.prototype.toPlainString = function toPlainString(preserveHm){
465
465
  var str=this.toYmdHmsMm();
466
466
  var prune = function(what){
467
467
  if(str.substr(str.length-what.length)==what){
@@ -471,7 +471,7 @@ bestGlobals.Datetime.prototype.toPlainString = function toPlainString(){
471
471
  return false;
472
472
  }
473
473
  /* eslint no-unused-expressions: 0 */
474
- prune('000') && prune('.000') && prune(':00') && prune(' 00:00');
474
+ prune('000') && prune('.000') && prune(':00') && (preserveHm || prune(' 00:00'));
475
475
  return str;
476
476
  }
477
477
  // bestGlobals.Datetime.prototype.toUTCString = function toUTCString(){ return this.iso; }
@@ -855,12 +855,26 @@ bestGlobals.registerJson4All = function registerJson4All(JSON4all){
855
855
  }else{
856
856
  return date.getTime();
857
857
  }
858
- }
858
+ },
859
+ serialize: function serialize(date){
860
+ return date.isRealDate ? date.toYmd() : date.toISOString();
861
+ },
862
+ deserialize: JSON4all.DateFunctions.deserialize,
863
+ valueLike:true
859
864
  });
860
865
  JSON4all.addType('date', {
861
866
  construct: function construct(value){
862
867
  return bestGlobals.date.iso(value);
863
868
  },
869
+ serialize: function serialize(o){
870
+ return o.toYmd();
871
+ },
872
+ deserialize: function deserialize(plainValue){
873
+ var ok = /^\d{4}-\d\d-\d\d$/.test(plainValue);
874
+ var value = ok && bestGlobals.date.iso(plainValue) || null;
875
+ return {ok, value};
876
+ },
877
+ valueLike:true
864
878
  });
865
879
  JSON4all.addType(bestGlobals.Datetime, {
866
880
  construct: function construct(value){
@@ -869,6 +883,15 @@ bestGlobals.registerJson4All = function registerJson4All(JSON4all){
869
883
  deconstruct: function construct(datetime){
870
884
  return datetime.toPlainString();
871
885
  },
886
+ serialize: function serialize(datetime){
887
+ return datetime.toPlainString(true);
888
+ },
889
+ deserialize: function deserialize(plainValue){
890
+ var ok = /^\d{4}-\d\d-\d\d \d\d:\d\d(:\d\d(.\d+)?)?$/.test(plainValue);
891
+ var value = ok && bestGlobals.datetime.iso(plainValue) || null;
892
+ return {ok, value};
893
+ },
894
+ valueLike:true
872
895
  });
873
896
  };
874
897
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-globals",
3
3
  "description": "common global function and constants - i.e. coalesce",
4
- "version": "1.0.4",
4
+ "version": "1.1.0",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/best-globals",