~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/mod/itu/shl/AsnUtc.cpp

  • Committer: Package Import Robot
  • Author(s): Nobuhiro Iwamatsu
  • Date: 2015-07-11 02:00:35 UTC
  • mfrom: (10.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150711020035-2nhpztq7s15qyc0v
Tags: 2.5.1-1
* New upstream release. (Closes: #789968)
* Update debian/control.
  - Update Standards-Version to 3.9.6.
* Add support mips64(el) and ppc64el. (Closes: #741508, #748146)
* Add patches/support-gcc-5.x.patch. (Closes: #777767)
  - Fix build with gcc-5.x.
* Add patches/Disable-NET0001.als.patch.
  - Disable test of NET0001.als.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
// - the copyright holder be liable for any  direct, indirect, incidental or -
12
12
// - special damages arising in any way out of the use of this software.     -
13
13
// ---------------------------------------------------------------------------
14
 
// - copyright (c) 1999-2012 amaury darsch                                   -
 
14
// - copyright (c) 1999-2015 amaury darsch                                   -
15
15
// ---------------------------------------------------------------------------
16
16
 
17
17
#include "Date.hpp"
21
21
#include "AsnNode.hxx"
22
22
#include "Utility.hpp"
23
23
#include "Boolean.hpp"
 
24
#include "Integer.hpp"
24
25
#include "Runnable.hpp"
25
26
#include "QuarkZone.hpp"
26
27
#include "Exception.hpp"
33
34
  
34
35
  // the base regex
35
36
  static const String ASN_UTC_BASE = 
36
 
    "($d$d$d$d)($d$d)($d$d)($d$d)($d$d)([$d$d]?)";
 
37
    "($d$d)($d$d)($d$d)($d$d)($d$d)([$d$d]?)";
37
38
  // the zone part regex
38
39
  static const String ASN_UTC_ZONE = "([<+->$d$d$d$d]?)";
39
40
  // the zulu part regex
46
47
      throw Exception ("asn-error", "invalid internal time regex object");
47
48
    }
48
49
    // check if we have the zulu time
49
 
    String zval = re.getstr (6);
 
50
    String zval = re.getstring (6);
50
51
    return (zval == 'Z');
51
52
  }
52
53
 
57
58
      throw Exception ("asn-error", "invalid internal time regex object");
58
59
    }
59
60
    // check if we have the seconds
60
 
    String sval = re.getstr (5);
 
61
    String sval = re.getstring (5);
61
62
    return (sval.isnil () == false);
62
63
  }
63
64
 
69
70
    bool sflg = asn_get_sflg (re);
70
71
    // get the date component2
71
72
    long year = re.getlong (0);
 
73
    if (year < 50) {
 
74
      year += 2000;
 
75
    } else {
 
76
      year += 1900;
 
77
    }
72
78
    long ymon = re.getlong (1);
73
79
    long mday = re.getlong (2);
74
80
    long hour = re.getlong (3);
86
92
    bool sflg = asn_get_sflg (re);
87
93
    // get the date component2
88
94
    long year = re.getlong (0);
 
95
    if (year < 50) {
 
96
      year += 2000;
 
97
    } else {
 
98
      year += 1900;
 
99
    }
89
100
    long ymon = re.getlong (1);
90
101
    long mday = re.getlong (2);
91
102
    long hour = re.getlong (3);
100
111
  // convert a regex value into a zone part
101
112
  static long asn_get_zone (const Regex& re) {
102
113
    // check for existence
103
 
    String zval = re.getstr (6);
 
114
    String zval = re.getstring (6);
104
115
    if (zval.isnil () == true) return 0L;
105
116
    // extract the zone component
106
117
    const Regex zre ("<+->($d$d)($d$d)");
304
315
  void AsnUtc::setdate (const String& sval) {
305
316
    wrlock ();
306
317
    try {
 
318
      char* sbuf = sval.tochar ();
 
319
      if (sbuf == nilp) sbuf = nilp;
307
320
      // check for local time or zulu
308
321
      Regex lre (ASN_UTC_BASE + ASN_UTC_ZULU);
309
322
      if (lre == sval) {
337
350
    }
338
351
  }
339
352
 
 
353
  // get a time representation
 
354
 
 
355
  t_long AsnUtc::totime (void) const {
 
356
    rdlock ();
 
357
    try {
 
358
      t_long result = d_tclk;
 
359
      unlock ();
 
360
      return result;
 
361
    } catch (...) {
 
362
      unlock ();
 
363
      throw;
 
364
    }
 
365
  }
 
366
    
340
367
  // get a string representation
341
368
 
342
369
  String AsnUtc::tostring (void) const {
347
374
      if (d_utcf == false) wclk -= d_zone;
348
375
      // format the date
349
376
      String result = Date::todfmt (wclk, "", "", "");
 
377
      // remove first 2 years digits
 
378
      result = result.rsubstr (2);
350
379
      // eventually remove the seconds
351
 
      if (d_sflg == false) result = result.lsubstr (12);
 
380
      if (d_sflg == false) result = result.lsubstr (10);
352
381
      // add the zulu part if needed
353
382
      if (d_utcf == true) result += "Z";
354
383
      // add the zone part if needed
367
396
  // -------------------------------------------------------------------------
368
397
 
369
398
  // the quark zone
370
 
  static const long QUARK_ZONE_LENGTH = 2;
 
399
  static const long QUARK_ZONE_LENGTH = 3;
371
400
  static QuarkZone  zone (QUARK_ZONE_LENGTH);
372
401
 
373
402
  // the object supported quarks
374
403
  static const long QUARK_UTCP     = zone.intern ("utc-p");
 
404
  static const long QUARK_TOTIME   = zone.intern ("to-time");
375
405
  static const long QUARK_TOSTRING = zone.intern ("to-string");
376
406
 
377
407
  // create a new object in a generic way
413
443
    // check for 0 argument
414
444
    if (argc == 0) {
415
445
      if (quark == QUARK_UTCP)     return new Boolean (isutc ());
 
446
      if (quark == QUARK_TOTIME)   return new Integer (totime ());
416
447
      if (quark == QUARK_TOSTRING) return new String  (tostring ());
417
448
    }
418
449
    // call the asn node method