/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 public static Couchbase.Lite.Document CreateTask(Database database, string title, 
     Bitmap image, string listId)
 {
     SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
         );
     Calendar calendar = GregorianCalendar.GetInstance();
     string currentTimeString = dateFormatter.Format(calendar.GetTime());
     IDictionary<string, object> properties = new Dictionary<string, object>();
     properties.Put("type", DocType);
     properties.Put("title", title);
     properties.Put("checked", false);
     properties.Put("created_at", currentTimeString);
     properties.Put("list_id", listId);
     Couchbase.Lite.Document document = database.CreateDocument();
     UnsavedRevision revision = document.CreateRevision();
     revision.SetUserProperties(properties);
     if (image != null)
     {
         ByteArrayOutputStream @out = new ByteArrayOutputStream();
         image.Compress(Bitmap.CompressFormat.Jpeg, 50, @out);
         ByteArrayInputStream @in = new ByteArrayInputStream(@out.ToByteArray());
         revision.SetAttachment("image", "image/jpg", @in);
     }
     revision.Save();
     return document;
 }
Пример #2
0
 /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 public static Couchbase.Lite.Document CreateNewList(Database database, string title, string userId)
 {
     var dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
     var calendar = Calendar.CurrentEra;
     string currentTimeString = dateFormatter.Format(calendar.GetTime());
     IDictionary<string, object> properties = new Dictionary<string, object>();
     properties.Put("type", "list");
     properties.Put("title", title);
     properties.Put("created_at", currentTimeString);
     properties.Put("owner", "profile:" + userId);
     properties.Put("members", new AList<string>());
     Couchbase.Lite.Document document = database.CreateDocument();
     document.PutProperties(properties);
     return document;
 }
Пример #3
0
		private string Iso(PersonIdent id)
		{
			SimpleDateFormat fmt;
			fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
			fmt.SetTimeZone(id.GetTimeZone());
			return fmt.Format(id.GetWhen());
		}
Пример #4
0
		public override string ToString()
		{
			StringBuilder r = new StringBuilder();
			SimpleDateFormat dtfmt;
			dtfmt = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z", CultureInfo.InvariantCulture
				);
			dtfmt.SetTimeZone(GetTimeZone());
			r.Append("PersonIdent[");
			r.Append(GetName());
			r.Append(", ");
			r.Append(GetEmailAddress());
			r.Append(", ");
			r.Append(dtfmt.Format(Sharpen.Extensions.ValueOf(when)));
			r.Append("]");
			return r.ToString();
		}
Пример #5
0
		private static string Date_format(double t, int methodId)
		{
			StringBuilder result = new StringBuilder(60);
			double local = LocalTime(t);
			if (methodId != Id_toTimeString)
			{
				AppendWeekDayName(result, WeekDay(local));
				result.Append(' ');
				AppendMonthName(result, MonthFromTime(local));
				result.Append(' ');
				Append0PaddedUint(result, DateFromTime(local), 2);
				result.Append(' ');
				int year = YearFromTime(local);
				if (year < 0)
				{
					result.Append('-');
					year = -year;
				}
				Append0PaddedUint(result, year, 4);
				if (methodId != Id_toDateString)
				{
					result.Append(' ');
				}
			}
			if (methodId != Id_toDateString)
			{
				Append0PaddedUint(result, HourFromTime(local), 2);
				result.Append(':');
				Append0PaddedUint(result, MinFromTime(local), 2);
				result.Append(':');
				Append0PaddedUint(result, SecFromTime(local), 2);
				// offset from GMT in minutes.  The offset includes daylight
				// savings, if it applies.
				int minutes = (int)Math.Floor((LocalTZA + DaylightSavingTA(t)) / msPerMinute);
				// map 510 minutes to 0830 hours
				int offset = (minutes / 60) * 100 + minutes % 60;
				if (offset > 0)
				{
					result.Append(" GMT+");
				}
				else
				{
					result.Append(" GMT-");
					offset = -offset;
				}
				Append0PaddedUint(result, offset, 4);
				if (timeZoneFormatter == null)
				{
					timeZoneFormatter = new SimpleDateFormat("zzz");
				}
				// Find an equivalent year before getting the timezone
				// comment.  See DaylightSavingTA.
				if (t < 0.0)
				{
					int equiv = EquivalentYear(YearFromTime(local));
					double day = MakeDay(equiv, MonthFromTime(t), DateFromTime(t));
					t = MakeDate(day, TimeWithinDay(t));
				}
				result.Append(" (");
				DateTime date = Sharpen.Extensions.CreateDate((long)t);
				lock (timeZoneFormatter)
				{
					result.Append(timeZoneFormatter.Format(date));
				}
				result.Append(')');
			}
			return result.ToString();
		}
Пример #6
0
 public virtual DateTime? GetDate(int tagType, [CanBeNull] TimeZoneInfo timeZone)
 {
     object o = GetObject(tagType);
     if (o == null)
     {
         return null;
     }
     if (o is DateTime)
     {
         return (DateTime)o;
     }
     if (o is string)
     {
         // This seems to cover all known Exif date strings
         // Note that "    :  :     :  :  " is a valid date string according to the Exif spec (which means 'unknown date'): http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/datetimeoriginal.html
         string[] datePatterns = new string[] { "yyyy:MM:dd HH:mm:ss", "yyyy:MM:dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm" };
         string dateString = (string)o;
         foreach (string datePattern in datePatterns)
         {
             try
             {
                 DateFormat parser = new SimpleDateFormat(datePattern);
                 if (timeZone != null)
                 {
                     parser.SetTimeZone(timeZone);
                 }
                 return parser.Parse(dateString);
             }
             catch (ParseException)
             {
             }
         }
     }
     // simply try the next pattern
     return null;
 }
Пример #7
0
		private static string HttpNow()
		{
			string tz = "GMT";
			SimpleDateFormat fmt;
			fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", CultureInfo.InvariantCulture
				);
			fmt.SetTimeZone(Sharpen.Extensions.GetTimeZone(tz));
			return fmt.Format(new DateTime()) + " " + tz;
		}
Пример #8
0
 /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 public static Couchbase.Lite.Document CreateProfile(Database database, string userId
     , string name)
 {
     SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
         );
     Calendar calendar = GregorianCalendar.GetInstance();
     string currentTimeString = dateFormatter.Format(calendar.GetTime());
     IDictionary<string, object> properties = new Dictionary<string, object>();
     properties.Put("type", DocType);
     properties.Put("user_id", userId);
     properties.Put("name", name);
     Couchbase.Lite.Document document = database.GetDocument("profile:" + userId);
     document.PutProperties(properties);
     return document;
 }
Пример #9
0
		public virtual string GetAtimeString()
		{
			SimpleDateFormat locale = new SimpleDateFormat();
			return (locale.Format(Sharpen.Extensions.CreateDate(atime)));
		}
Пример #10
0
		private string Get_time_stamp()
		{
			SimpleDateFormat f = new SimpleDateFormat(" 'Last update:' yyyy-MM-dd HH:mm:ss z");
			return f.Format(new DateTime());
		}